vba - Looping through all files in a folder (encountering run time error '-2147221080 (800401a8)') -
i running code aims pull in data workbooks within specific folder. have written code loop separate code pulling in of data.
sub fixedincomeloop() dim file variant dim wb1 workbook dim wb2 workbook dim folderpath string dim ws worksheet dim ws2 worksheet set wb1 = activeworkbook set ws = activesheet folderpath = "c:\users\wei hong\documents\trade tickets\" file = dir(folderpath) while (file <> "") set wb2 = workbooks.open(file) set ws2 = wb2.worksheets("trade ticket") call fixedincome(wb1, ws, ws2) wb2.close savechanges:=false set wb2 = nothing wend end sub private sub fixedincome(wb1 workbook, ws worksheet, ws2 worksheet) dim ws3 worksheet set ws3 = wb1.worksheets("constants") <-- facing error ws.activate ... end sub
i facing runtime error above. not sure why!
Comments
Post a Comment