excel - Looping through files in directory with Dir function, just hits same file over and over -


this question has answer here:

i have spreadsheet looks through several other spreadsheets in given directory extract statistics them. far, gets first file , hits on , on again.

my code goes this:

public sub getresults()     const strdirectory string = "somenetworklocation"     dim strfilename string      strfilename = dir(strdirectory & "*.xl??")      while strfilename <> ""          if strfilename "somematchingscheme_##_??"             workbooks.open strdirectory & strfilename              'do stuff workbook              workbooks(strfilename).close         end if     loop end sub 

any suggestions?

you need call again

strfilename = dir  ' no parameters 

before loop. call iterate strfilename next file. without it, stick first found file.


Comments