Different Headers but Same Footer for Each Section

How would I create a document that has two sections where the headers are different but the footers are the same? For example, I would have the first section be labeled "Header 1" and the second section be labeled "Header 2" but the footer for both of those sections would be the same, in this case, "Author: John Apples."

I am working in MS Excel since I want to import some data from a sheet.

NOTE: I am very new to VBA

I tried using the "DifferentHeaderFirstPageHeaderFooter = True" but that applies to both the header and footer, not just the header. Also, I don't believe I am creating separate sections so it would be nice to have that feature implemented since I plan to add more sections that would have different headers. Any help would be greatly appreciated.

My Code

'Create a new Doc
Set myDocument = WordApp.Documents.Add
WordApp.Visible = True
WordApp.Activate

'Set Landscape Orientation
myDocument.PageSetup.Orientation = 1

'Set Margins
myDocument.PageSetup.BottomMargin = 26
myDocument.PageSetup.TopMargin = 26
myDocument.PageSetup.LeftMargin = 36
myDocument.PageSetup.RightMargin = 36

myDocument.Styles("Footer").Font.Size = 9
myDocument.Styles("Header").Font.Size = 18
myDocument.Styles("Header").Font.Color = RGB(0, 98, 155)

Set objSelection = WordApp.Selection

'Creating the header
objSelection.Sections(1).Headers(wdHeaderFooterPrimary).Range.InsertBefore "Header 1"
objSelection.Sections(1).Headers(wdHeaderFooterFirstPage).Range.InsertBefore "Header 2"

'Add Footer and Page Numbers
objSelection.Sections(1).Footers(WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.InsertBefore "Author: John Apples"
objSelection.Sections(1).Footers(WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range.InsertBefore "Author: John Apples"
        
objSelection.Sections(1).Footers(wdHeaderFooterFirstPage).PageNumbers.ShowFirstPageNumber = True
objSelection.Sections(1).Footers(wdHeaderFooterPrimary).PageNumbers.Add FirstPage:=True

        
objSelection.Font.Name = "Arial"
objSelection.Font.Size = 12
objSelection.Font.Color = RGB(0, 98, 155)
        
myDocument.Sections.First.PageSetup.DifferentFirstPageHeaderFooter = True

UPDATE:

https://i.stack.imgur.com/Ko9rd.png

https://i.stack.imgur.com/GWPPu.png

These two photos are what I would like the end product to look like.



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation