Excel: VBA to print to PDF - Run time error 1004

后端 未结 5 2157
谎友^
谎友^ 2021-01-07 10:32

I have tried using the following solution to print from Excel to PDF:

Excel 2013 Print to PDF in VBA

While the solution seems to have worked for other people

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-07 10:53

    So this is the working code now for Windows users (Mac OS might have to adjust file path):

    Sub Invoice_to_PDF()
    'Saves the invoice print area to a PDF file
    
    Dim fp As String
    Dim wb As Workbook
    Dim ws As Worksheet
    
    fp = "C:\Users\[username]\Desktop\NewInvoice.pdf"
    Set wb = ActiveWorkbook
    Set ws = Worksheets("Invoice")
    
    ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fp, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
    
    
    End Sub
    

提交回复
热议问题