kazzi
kazzi

Reputation: 534

Converting Individual Excel Sheets as Individual PDF Files

I am just trying to use VBA to create create/save individual excel sheets as individual PDF files.

I came across this online:

Sub SaveWorksheetsAsPDFs()
Dim sFile       As String
Dim sPath       As String
Dim wks         As Worksheet

With ActiveWorkbook
    sPath = .Path & "\"
    For Each wks In .Worksheets
            sFile = wks.Name & ".pdf"
            wks.ExportAsFixedFormat Type:=xlTypePDF, _
                                    Filename:=sPath & sFile, _
                                    Quality:=xlQualityStandard, _
                                    IncludeDocProperties:=False, _
                                    IgnorePrintAreas:=False, _
                                    OpenAfterPublish:=False
    Next wks
End With
End Sub

However, I'm getting the following error:

Run-time error '5': Invalid procedure call or argument

For someone not 100% familiar with VBA, what's invalid?

Thanks

Upvotes: 0

Views: 466

Answers (1)

Gary's Student
Gary's Student

Reputation: 96791

As I said in my comment, your code runs fine (Win-10, Excel-365). I first:

Saved the .xlsm file to insure Spath exists
Selected an area on each worksheet to insure it will be PDF'ed correctly

Upvotes: 2

Related Questions