I am attempting to loop through files using Dir
. I have written the following, but as expected, the loop is endless as it opens and closes the first file in the folder.
I am wondering if there is a better way than the wildcard method, but can anyone offer me a solution to this.
strFolder = "D:\Name\Project\Data\Back-End\Previous\"
strFileSpec = strFolder & "*.xlsx"
strFileName = Dir(strFileSpec)
Do While Len(strFileName) > 0
Dim strFilePath As String: strFilePath = strFolder & strFileName
Set proxy_wbk = Workbooks.Open(strFilePath)
Set proxySheet = proxy_wbk.Sheets(1)
siteName = proxySheet.Cells(1, 1).Value
'do work'
Workbooks(siteName & "_Jan_2017.xlsx").Close savechanges:=False
Loop