My macro is supposed to go through every worksheet in the workbook and save them as a PDF, but it will only work for 5 worksheets and then errors out (there are 107 total worksheets in the workbook). Any ideas what I'm doing wrong?
Sub Macro1()
Dim ws As Worksheet
Dim starting_ws As Worksheet
Set starting_ws = ActiveSheet
For Each ws In ThisWorkbook.Worksheets
ws.Activate
Dim saveLocation As String
saveLocation = "C:\Users\James Pencek\Documents\Invoices" & ActiveSheet.Name & " " & Format(Now(), "MMM. YY") & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=saveLocation
Next
starting_ws.Activate
End Sub
Sub Macro1()
Dim ws As Worksheet
Dim starting_ws As Worksheet
Set starting_ws = ActiveSheet
For Each ws In ThisWorkbook.Worksheets
ws.Activate
Dim saveLocation As String
saveLocation = "C:\Users\James Pencek\Documents\Invoices" & ActiveSheet.Name & " " & Format(Now(), "MMM. YY") & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=saveLocation
Next
starting_ws.Activate
End Sub