Sub MyCreatePDF()
'
' PDF generating Macro
'
On Error GoTo MyCreatePDFErr
Dim strTheFileSaveName As String
TheFileName = "File_" & ActiveWorkbook.Names("MyNamedRange").RefersToRange & ".PDF"
'open file save dialog to create a apth and name to save the PDF to
' strTheFileSaveName = Application.GetSaveAsFilename(InitialFileName:=ActiveWorkbook.Names("PDF_Path").RefersToRange & "HSS_" & ActiveWorkbook.Names("MyNamedRange").RefersToRange & "_Txn", _
' filefilter:="PDF (Adobe PDF) (*.pdf), *.Pdf", Title:="Please enter PDF filename to export to")
'
' 'pressed the cancel button
' If strTheFileSaveName = "False" Then
' MsgBox "PDF creation aborted no file will be produced ", , "CMF Trade PDF Creation"
' Exit Sub
' End If
Application.ScreenUpdating = False
'in order to produce the PDF the sheet has to be visible
ActiveWorkbook.Sheets("pdf").Visible = True
ActiveWorkbook.Sheets("pdf").Select
ActiveWorkbook.Sheets("pdf").Range("B3:E33").Activate ' area of PDF
' system footer HSBC
With ActiveSheet.PageSetup
.LeftFooter = "RESTRICTED - &D" & " " & "&T" & " " & varVersionStamp
End With
'produce the PDF from the sheet
' ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strTheFileSaveName, _
' Quality:=xlQualityMinimum, IncludeDocProperties:=False, IgnorePrintAreas:=True, OpenAfterPublish:=True
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=TheFileName, _
Quality:=xlQualityMinimum, IncludeDocProperties:=False, IgnorePrintAreas:=True, OpenAfterPublish:=True
DoEvents
'save the file name
gblstrPDFName = strTheFileSaveName
DoEvents
ActiveWorkbook.Sheets("pdf").Visible = False
DoEvents
Application.ScreenUpdating = True
Exit Sub
MyCreatePDFErr:
MsgBox "This error : " & Err & " :" & Error & vbNewLine & vbNewLine & " This has stopped the PDF production process " & _
vbNewLine & vbNewLine & " Please contact your system Administrator or support function.", vbCritical, "PDF Creation"
Application.ScreenUpdating = True
Exit Sub
End Sub