Hi,
I have been using this code to save up to 70 tabs into separate PDFs on a monthly basis for at least a year. There is a "Save to PDF" button on one of the worksheets that runs the macro. I have never had any issues with it but today when I clicked the button to save all the sheets as PDFs, Excel would instantly close and reopen without any errors. I did the Quick Repair option for Office 365 but that didn't solve it. I haven't found anything online to help me. Below is the code. Why does Excel crash without warning or error when it ran just fine last month?
The code looks at cell J1 on each worksheet and if there is a number "1" there, it will save that tab as a PDF in the directory that the Excel file is currently saved in.
Option Explicit
Private Sub SavePDFFuture()
Application.ScreenUpdating = False
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
If ws.Range("J1") = 1 Then
ws.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=ActiveWorkbook.Path & "\" & "PPRFuture_" & ws.Name & " " & Worksheets("Summary").Range("L1"), _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End If
Next ws
Application.ScreenUpdating = True
End Sub
**********UPDATE***********
I tried one more thing. I changed the save directory to be an actual directory rather than "ActiveWorkbook.Path" and it worked. Why? I have no clue. I am keeping this post here in case other people have the same issue.
Bookmarks