Select all sheets and print into single pdf file

2019-07-15 12:33发布

I want to print all sheets to a single pdf file. an each sheet would be on the beginning of new page.

I've tried with:

Private Sub CommandButton9_Click()

 ActiveWorkbook.Sheets.Select
 With Selection
 .ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
 "E:\tempo.pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, _
 IgnorePrintAreas:=False, OpenAfterPublish:=True
End With

End Sub

I've got a message :"Method 'Select' of object 'Sheets' failed."

Thanks!

1条回答
Summer. ? 凉城
2楼-- · 2019-07-15 13:31

instead of activesheet.export... Use activeworkbook.export... Each sheet will display by how you have the print setup for each sheet set.

Or use Variables such as:

Sub Button1_Click()
    Dim wb As Workbook, Fnm As String

    Set wb = ThisWorkbook
    Fnm = "C:\Users\Dave\Downloads\TestMe.pdf"

    wb.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Fnm

End Sub
查看更多
登录 后发表回答