I am trying to create a macro that will allow me to import data from all files ending in ".xlsx" in a specified folder into a single spreadsheet. I've mostly figured it out, but there's a recurring issue that requires a manual work-around until I figure out a solution.
The source .xlsx files contain a standard template for inputting data and are populated and submitted to me by other users. I download these files into a specified folder on my computer. However, the Dir function does not recognize any of the .xlsx files in the specified folder unless I open the file in Excel and click "Save". Once I do that, the Dir function works perfectly and all the .xlsx files are listed in the Immediate window. I'd appreciate any insight anyone has regarding why this is happening and if there's any way to fix the code so it recognizes the files without opening and saving.
Sub Test()
Dim strPath As String
Dim strFile As String
strPath = ActiveWorkbook.Path & Application.PathSeparator & "ReferenceFolderName" & Application.PathSeparator
strFile = Dir(strPath, MacID("XLSX"))
Do While Len(strFile) > 0
strFile = Dir
Debug.Print strFile
Loop
End Sub