Home > Software design >  SaveAs PDF and open in Adobe Reader as new Tab
SaveAs PDF and open in Adobe Reader as new Tab

Time:11-24

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?

CodePudding user response:

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

I suppose that you do not try exporting the same sheet. In such a case you may use the sheet names (being unique) to name the exported pdf.

  • Related