Solved

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

Posted on 2013-05-22
4
1,192 Views
Last Modified: 2013-06-17
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
Comment
Question by:CFMI
  • 3
4 Comments
 
LVL 84
ID: 39189364
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
 
LVL 1

Author Comment

by:CFMI
ID: 39190760
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
 
LVL 1

Accepted Solution

by:
CFMI earned 0 total points
ID: 39205426
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
 
LVL 1

Author Closing Comment

by:CFMI
ID: 39252580
I discovered the code:
Worksheets("Sheet2").PageSetup.CenterHeader = _
"Some&B&""Courier New""&10 Bold Courier New Size 10&B&""Arial"" Text"
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now