选择所有工作表并打印到单个pdf文件中

时间:2015-10-05 09:59:21

标签: excel vba excel-vba

我想将所有工作表打印到单个pdf文件中。每张纸都在新页面的开头。

我试过了:

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

我收到了一条消息:"方法'选择'对象'表格'失败"

谢谢!

1 个答案:

答案 0 :(得分:1)

而不是activesheet.export... 使用activeworkbook.export... 每张纸将按照每张纸张的打印设置进行显示。

或使用变量,例如:

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