[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1352
  • Last Modified:

MS Access VBA to include headers and footers for a PDF file inside the creation VBA

Hello Experts,

Your assistance is needed regarding how to include a header and page numbers into a created PDF file.  

The goal is to include MS Access VBA statements within the creation, as well.  The code below creates a PDF file by using a Master Workbook with 53 worksheets.  I have been able to manually update the Master spreadsheet by adding the header and footer; however, the process should ultimately be automated.

Perhaps, adding a function to update the worksheet formats before creation would be an option?  For example, make every header for each worksheet the same name as the worksheet tab and all footers has a Page Number.

Private Sub Prepare_PDF_Click()
Dim MyFullName As String
Dim xlAppFTP As Object, xlWb As Object, xlWs As Object
Set xlAppFTP = CreateObject("Excel.Application")
Set xlWb = xlAppFTP.Workbooks.Open("H:\PDF\Master.xls")
MyFullName = "H:\PDF\MonthlyReport.pdf"

xlWb.ExportAsFixedFormat Type:=0, FileName:=MyFullName, _
Quality:=1, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

xlWb.Close
Set xlWs = Nothing
Set xlAppFTP = Nothing
Set xlApp = Nothing
MsgBox "The PDF file was created"

End Sub
0
CFMI
Asked:
CFMI
  • 3
1 Solution
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
What would your "header" consist of?

In most cases, the PDF software would create page numbers as needed. If you need to add page numbers arbitrarily, you'd have to define the logic for that, and work with that.
0
 
CFMIFinancial Systems AnalystAuthor Commented:
Experts,

Customer now, doesn't need Headers and the above code is used to create the PDF but that file doesn't include page numbers when the Excel worksheets format doesn't include Page Numbers.  Is there a way to include Page Numbers in the above code or am I stuck manually updating each worksheet?
0
 
CFMIFinancial Systems AnalystAuthor Commented:
Experts,

Below displays code to update a workbook to include page numbers, but is there a way to also include a Header?  For example, is there "CenterHeader " syntax?

Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
        ws.PageSetup.CenterFooter = "Page # &P"
Next
End Sub
0
 
CFMIFinancial Systems AnalystAuthor Commented:
I discovered the code:
Worksheets("Sheet2").PageSetup.CenterHeader = _
"Some&B&""Courier New""&10 Bold Courier New Size 10&B&""Arial"" Text"
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now