Hello,
I wrote a macro that looped through a folder of workbooks and performed a series of tasks on each one. My problem is that it opens a file called "DS_Store" and I get an error message because excel is unable to perform any of the tasks I need.
Here is the macro:
Sub Loopfolder_All_Arizona()
Dim wbResults As Workbook
Dim wbCodeBook As Workbook
Dim strPath As String
Dim strFile As String
Dim i As Integer
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.EnableEvents = False
End With
Set wbCodeBook = ThisWorkbook
'Define the path to your folder
strPath = "Macintosh HD:Users:TSM:Desktop:TESTLOOP FOLDER:"
'Ensure that the path ends in a backslash
If Right(strPath, 1) <> ":" Then strPath = strPath & ":"
'Call the first file within the folder (change the file extension, accordingly)
strFile = Dir(strPath & "*.xlsx")
'Loop through each file within the folder
Do While Len(strFile) > 0
'Open the current file
Set wbResults = Workbooks.Open(strPath & strFile)
Application.Calculation = xlAutomatic
Application.Run "'Personal Macro Workbook.xlsb'!Rename_all_worksheets"
Sheets("Sheet Names").Select
FPath = "Macintosh HD:Users:TSM:Documents:Convention:Databases:Arizona:Primaries:Counties"
FName = Sheets("Sheet Names").Range("A2").Text
ActiveWorkbook.SaveAs Filename:=FPath & ":" & FName
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = True
ActiveWorkbook.save
ActiveWorkbook.Close
strFile = Dir
Loop
With Application
.ScreenUpdating = True
.DisplayAlerts = True
.EnableEvents = True
End With
MsgBox "DONE"
End Sub
Bookmarks