Exporting sheet template to PDF generates Runtime Error 5: Invalid Procedure call or argument

前端 未结 4 1415
半阙折子戏
半阙折子戏 2021-01-22 13:03

I have created a macro to export the sheet template to PDF:

ActiveWorkbook.Sheets(\"Sheet2\").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
  ActiveWorkbook.         


        
相关标签:
4条回答
  • 2021-01-22 13:34

    if you have adobe printer installed then just use below code to get a pdf

    sub Sample()
        ActiveWorkbook.Sheets("Sheet2").Activate
        ActiveSheet.Printout
    End Sub
    
    0 讨论(0)
  • 2021-01-22 13:39

    Your actual code works for me. However try this (TRIED AND TESTED)

    Sub Sample()
        ActiveWorkbook.Sheets("Sheet2").Activate
    
        ActiveSheet.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=ActiveWorkbook.Path & "\Survey Report.pdf", _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=True
    End Sub
    

    Note:

    1. Also hope Sheet2 has something in it to print else a blank sheet will give you the error.
    2. If you want to print the sheet from the workbook where you are running the code then you might want to change ActiveWorkbook to ThisWorkbook and try again...
    0 讨论(0)
  • 2021-01-22 13:51

    I also got this error and tried doing it manually to work out the problem.

    Turns out that you can't save as PDF when the filename (including path) is longer than 218 characters.

    0 讨论(0)
  • 2021-01-22 13:51

    You also must have Excel's free Microsoft Save as PDF or XPS add-in installed.

    0 讨论(0)
提交回复
热议问题