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.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.PageSetup.Orientation = wdOrientPortrait

Open in new window

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

LVL 10
Who is Participating?
GrahamSkanConnect With a Mentor RetiredCommented:
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
ClifAuthor Commented:
That was exactly what I needed.  Thanks.

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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.