Error using ExportAsFixedFormat command

2019-09-01 06:57发布

I am trying to debug some code containing an ExportAsFixedFormat that is causing an "Automation error the object invoked has disconnected from its clients." error message. I am running in 2013 so don't need the PDF/XPS add-in and the function works elsewhere in the workbook. It seems to have something to do with the page I am trying to make the PDF out of. While the main macro is longer, I am having the same error occur when I use this simple piece of code:

Sub NewAssetScreen()

    Sheets("New Asset").Select
    Sheets("New Asset").Activate

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Quality:=xlQualityStandard, _
                                   IgnorePrintAreas:=False, OpenAfterPublish:=True

    Sheets("New Asset").Select
    Range("A1").Select

End Sub

However if I run the macro with a different worksheet name it works fine. The selection part seems to be ok - ie will work with that worksheet name but it is just the ExportAsFixedFormat command that won't work on the page.

Any insights as to why this might be the case?

Thanks in advance.

Nic

1条回答
Viruses.
2楼-- · 2019-09-01 07:54

Check page breaks and other things specific to that worksheet.
Try using Sheets("New Asset").ExportAsFixedFormat instead of ActiveSheet.
Lastly try copying and pasting the contents of the New Asset sheet to a new sheet and delete the old one.

查看更多
登录 后发表回答