I'm trying to use Mac Excel 2011 VBA to grab all .xls files in a directory and merge them. The trouble, however, isn't the merge algorithm; it's convincing VBA to properly identify and iterate through the files. I've tried a thousand things, but I can't get Excel to use the path to the folder.
Here is what I have:
Sub CombineSheetsFromAllFilesInADirectory()
Path = "Macintosh HD:Users:timben:Documents:datafiles"
Application.EnableEvents = False 'turn off events
Application.ScreenUpdating = False 'turn off screen updating
Set mWB = Workbooks.Add(1) 'create a new one-worksheet workbook
Set aWS = mWB.ActiveSheet 'set active sheet variable to only sheet in mWB
FileName = Dir(Path, MacID("XLS8")) ' set first file's name to filename variable
Do While Len(FileName) > 0
' Merge files
Loop
' Clean up
End Sub
It never enters the merge loops, as it never picks up any files from the directory. I know the path is right because I checked it with "MyPath = CurDir " in a debug routine.
Ideas? I tried XLS8 and XLS5 MacIDs, with no difference. It will work if I feed it Dir ("") instead of a path and XLS8, but that is clumsy and doesn't allow me to filter file types or set a path.
Here is what I have:
Sub CombineSheetsFromAllFilesInADirectory()
Path = "Macintosh HD:Users:timben:Documents:datafiles"
Application.EnableEvents = False 'turn off events
Application.ScreenUpdating = False 'turn off screen updating
Set mWB = Workbooks.Add(1) 'create a new one-worksheet workbook
Set aWS = mWB.ActiveSheet 'set active sheet variable to only sheet in mWB
FileName = Dir(Path, MacID("XLS8")) ' set first file's name to filename variable
Do While Len(FileName) > 0
' Merge files
Loop
' Clean up
End Sub
It never enters the merge loops, as it never picks up any files from the directory. I know the path is right because I checked it with "MyPath = CurDir " in a debug routine.
Ideas? I tried XLS8 and XLS5 MacIDs, with no difference. It will work if I feed it Dir ("") instead of a path and XLS8, but that is clumsy and doesn't allow me to filter file types or set a path.