?
Solved

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

Posted on 2013-05-22
4
Medium Priority
?
1,277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 85
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

764 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