Access Beginner
Active Member
- Joined
- Nov 8, 2010
- Messages
- 311
- Office Version
- 2016
- Platform
- Windows
Hello,
The following code creates a PDF document based off named ranges on cells. However it fails if the PDF document is already open.
Can someone please add error handling to this, so it will not bug out.
Code below is what VBA highlights and there is a yellow error next to this line "OpenAfterPublish:=True"
The following code creates a PDF document based off named ranges on cells. However it fails if the PDF document is already open.
Can someone please add error handling to this, so it will not bug out.
Code below is what VBA highlights and there is a yellow error next to this line "OpenAfterPublish:=True"
Code:
.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=ReportPath & ReportName & ".PDF", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
Code:
Sub PDFPrint()
Dim ReportPath As Variant
Dim ReportName As Variant
Dim ToPrint As Variant
Set ReportPath = Sheets("Menu").Range("A116")
Set ReportName = Sheets("Menu").Range("A52")
Set ToPrint = Sheets("Menu").Range("A55")
Worksheets("Overview5").Activate
With ActiveSheet
.PageSetup.PrintArea = ToPrint
.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=ReportPath & ReportName & ".PDF", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End With
End Sub