'Exporting sheets as pdf error: Run-time error '1004'. We didn't find anything to print

I'm trying to export all sheets in the workbook as separate pdf files using one button.

I followed a YouTube tutorial: https://www.youtube.com/watch?v=FRZ6n3gHt3k

I get:

Run-time error '1004'. We didn't find anything to print.

Sub Macro1()

Dim folder_path As String

With Application.FileDialog(msoFileDialogFolderPicker)
    .Title = "select the folder path"
    If .Show = -1 Then folder_path = .SelectedItems(1)
End With

Dim sh As Worksheet

For Each sh In ActiveWorkbook.Worksheets
    sh.ExportAsFixedFormat xlTypePDF, folder_path & 
    Application.PathSeparator & sh.Name & ".pdf"
Next

MsgBox "done"

End Sub


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source