Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SaveAs PDF and open in Adobe Reader as new Tab

I´m experiencing the following problem. To save an Excel Sheet as PDF, I´m using the following code.

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

This works perfectly fine the first time I´m executing the command. The File pops up as PDF format and is displayed in Adobe Acrobat Reader DC. But when I execute it again, without closing the opened PDF file, I´m getting an error. As long as I always close the old PDF, there is no error. I´m pretty sure it is possible to open the next files in new tabs within Acrobat Reader without getting these errors in VBA. Can someone help me out here?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

A file having the same name, cannot be open in the same session of most of applications…

Please, use the next way, which gives different names and opens the same sheet in three consecutive tabs:

Sub expSheetAsPDFAndOpen()
   Dim strPDF As String, i As Long
   strPDF = ThisWorkbook.path & "\MyPDF"
   For i = 1 To 3
        ActiveSheet.ExportAsFixedFormat _
             Type:=xlTypePDF, _
             Quality:=xlQualityStandard, _
             IncludeDocProperties:=True, _
             IgnorePrintAreas:=False, _
             FileName:=strPDF & i & ".pdf", _
             OpenAfterPublish:=True
  Next i
End Sub
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading