• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 315
  • Last Modified:

Automating Word - First Page Headers Appearing After Rotating a Page To Landscape

Using VB.Net 2010 (Pro) to create Word documents (either Word 2003 or 2010)

This is an offshoot from a previous question that can be found HERE.

I am creating a document that has a header/footer the appears on the first page, and a different header/footer that is to appear on all the other pages.  This has been working fine until now.

In the previous question noted above, I needed to be able to rotate a single page in the middle of the document to landscape.  I did, and that part works fine.  However there appears to be an artifact that was caused by the rotation.  On the page that rotated, as well as the following page (in my testing that following page is the last page of the document), the header and footer are the ones that are to appear on the first page.

Here's the code that "rotates" the page:
m_oDoc.Bookmarks.Item("\endofdoc").Range.InsertBreak(Type:=wdSectionBreakNextPage)
m_oDoc.Bookmarks.Item("\endofdoc").Range.PageSetup.Orientation = wdOrientLandscape

Open in new window

After this, comes the code that writes to the page
Then the code to return it back to portrait:
m_oDoc.Bookmarks.Item("\endofdoc").Range.InsertBreak(Type:=wdSectionBreakNextPage)
m_oDoc.Bookmarks.Item("\endofdoc").Range.PageSetup.Orientation = wdOrientPortrait

Open in new window


How do I get the correct header/footer to show up?

TIA
0
Clif
Asked:
Clif
1 Solution
 
CodeCruiserCommented:
0
 
GrahamSkanCommented:
Each section can have its own first page setting. By default, the settings for new sections are copied from the previous one, so in your case, when you create a new section, you will need to reset the different first page setting for the new sections

m_oDoc.Sections.Last.PageSetup.DifferentFirstPageHeaderFooter = False
0
 
ClifAuthor Commented:
GrahamSkan
That was exactly what I needed.  Thanks.

Code_Cruiser
I'm sure your link would have lead to a solution, but time is of the essence, so a code snippet wins out over a link.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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