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

前端 未结 4 1422
半阙折子戏
半阙折子戏 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: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...

提交回复
热议问题