excel - Searching a folder to match each file to a table -
i added loop (see k part) , slows down entire program. possible make more efficient?
i searching specific folder , trying match each file table in spreadsheet. trying make quarters(1,j) in k loop same quarters(i,j) lower part of code not sure how since have used integer i.
for j = 1 2 k = 1 39 if k <= 29 'looks @ files in folder given quarter sourcefoldername = folderpath & "\" & quarters(1, j) set objfso = createobject("scripting.filesystemobject") set objfolder = objfso.getfolder(sourcefoldername) end if if k > 29 sourcefoldername = folderpath & "\" & quarters(k, j) set objfso = createobject("scripting.filesystemobject") set objfolder = objfso.getfolder(sourcefoldername) end if each objfile in objfolder.files = 1 notassigned = true 'keep going until match file while notassigned = true 'if beginning of file name matches given state, 'assign file name state quarter if left(objfile.name, 9) = stateabbr(i, 1) & quarters(i, j) & "fa" wbname(i, j) = objfile.name 'stop trying match file notassigned = false end if if = 39 notassigned = false = + 1 wend next objfile set objfile = nothing set objfolder = nothing set objfso = nothing next k next j
i managed change entire code use dir instead of looping each cell in spreadsheet , looping each file in folder. run time cut down 40 min 2 second!!!!!!! amazed now. here solution if interested.
dim strfile string j = 1 2 = 1 39 strfile = dir(folderpath & "\" & quarters(i, j) & "\*fa*") while len(strfile) > 0 if left(strfile, 9) = stateabbr(i, 1) & quarters(i, j) & "fa" wbname(i, j) = strfile end if strfile = dir loop next next j
Comments
Post a Comment