Macro to save as PDF

Copper Contributor

HI Everyone,

 

I have been running the macro below for a few months now without any problems:

 

Today when I tried to run the macro I received this error message - Run-time error 'S': Invalid procedure call or argument.

 

The error occurs at the red text.

 

Macro:

 

Sub LoopSheetsSaveAsPDF()

 

Dim ws As Worksheet


For Each ws In ActiveWorkbook.Worksheets

 

ws.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=ThisWorkbook.Path & "/" & ws.Name & ".pdf"

 

Next

 

End Sub

3 Replies

@Bill_A2B 

 

Are there any empty sheets in the workbook, if so delete them.

@Jihad Al-Jarady Thank you. 

 

There were no empty worksheets, however, there were hidden worksheets. I unhide these and the macro now works as expected.

 

Your suggestion of removing empty worksheets led me in the right direction.

@Bill_A2B 

 

I am glad you managed to fix it.