Adding different headers and footers in Microsoft word

Good day


Is it possible to have different headers and footers for a landscape and portrait page in one document, thus when you add a landscape page it needs to automatically use the landscape header and footer?

We've looked into section breaks, but then one needs to add a new header manually…


Or is there another way to set up a document to make it issue to switch between headers and footers for different pages?

You must have section breaks in order to change the page orientation from portrait to landscape or vice versa. If you create your headers/footers using alignment tabs (see http://office.microsoft.com/en-us/word-help/master-headers-and-footers-in-long-word-2007-documents-HA010234134.aspx#BMalignment), they will adjust to the margin width.

Microsoft MVP (Word) since 1999
Fairhope, Alabama USA
http://ssbarnhill.com
http://wordfaqs.ssbarnhill.com
Screen shots captured with TechSmith's Snagit

1 person found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

We are currently using section breaks only for changing the page orientation, but for the headers and footers we found that if we use section breaks, every time we press enter on for instance the landscape page it adds a portrait page with its own header and footer instead of another landscape page, it adds an Odd/Even page break, so then we have to in any case change the header and footer manually, which is not quite what we want

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

You need to manually insert a pair of section breaks, one at the start and the other at the end of the change in page orientation.  You can select continuous or next page break, but with the change in orientation it will automatically become a next page.

Inserting a Break with a Macro

http://word.tips.net/T000744_Inserting_a_Break_with_a_Macro.html

Summary: Inserting a break in your document is easy. You may think that inserting one using a macro is more complex, but it isn't. Just use the InsertBreak method, described in this tip. (This tip works with Word 97 | 2000 | 2002 | 2003 | 2007.)

You know how to insert breaks in your text using menu commands, but you can also do the same thing under control of your macro. The InsertBreak method inserts any type of break in your document. The syntax is:

Selection.InsertBreak Type:=BreakValue

where BreakValue is one of the following values:

BreakValue

Result

wdPageBreak

Page break

wdColumnBreak

Column break

wdSectionBreakNextPage

Next-page section break

wdSectionBreakContinuous

Continuous section break

wdSectionBreakEvenPage

Even-page section break

wdSectionBreakOddPage

Odd-page section break

wdLineBreak

Line break




You could use these macros to insert the breaks for you, rather than mousing it
Separate File by Section

The following macro copies text one section at a time and saves that text in a new document. The macro uses the pre-defined bookmark \section to create the new document. This macro is useful for breaking up a mail merge "Merge to New Document" file.

Sub BreakOnSection()

   ' Used to set criteria for moving through the document by section.

   Application.Browser.Target = wdBrowseSection

 

   'A mailmerge documents ends with a section break next page.

   'Subtracting one from the section count stop error message.

   For i = 1 To ((ActiveDocument.Sections.Count) - 1)

  

      'Select and copy the section text to the clipboard

      ActiveDocument.Bookmarks("\Section").Range.Copy

 

      'Create a new document to paste text from clipboard.

      Documents.Add

      Selection.Paste

 

   ' Removes the break that is copied at the end of the section, if any.

      Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend

      Selection.Delete Unit:=wdCharacter, Count:=1

ChangeFileOpenDirectory "C:\"

      DocNum = DocNum + 1

     ActiveDocument.SaveAs FileName:="test_" & DocNum & ".doc"

     ActiveDocument.Close

      ' Move the selection to the next section in the document

     Application.Browser.Next

   Next i

   ActiveDocument.Close savechanges:=wdDoNotSaveChanges

End Sub

NOTE: When you use this code to select and copy the text content of the document, the header and footer are not retained. Styles, fonts and layout may change if the main file and the new document are from different templates, but direct formatting is maintained.

Insert Section Break before a Style

http://answers.microsoft.com/en-us/office/forum/office_2010-word/splitting-a-word-document/a7c8f352-1279-495a-a354-841d141537f8#footer

Macro to be used with the Separate by Style tip.

Here is a macro to insert a section break before every Heading 1 paragraph (except at the beginning of the document). You can change the stye if you like

Sub CreateSections()
    Application.ScreenUpdating = False
    Selection.HomeKey Unit:=wdStory
    With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Format = True
        ' You can specify another style if you like
        .Style = ActiveDocument.Styles(wdStyleHeading1)
        .Forward = True
        .Wrap = wdFindStop
        Do While .Execute
            Selection.Collapse
            If Selection.Start > 0 Then
                Selection.InsertBreak Type:=wdSectionBreakNextPage
            End If
            .Execute
        Loop
    End With
    Application.ScreenUpdating = True
End Sub

BTW, if you insert one section break manually, you can copy it, then enter ^c in the Replace With box to refer to the contents of the clipboard. So in this example, you could use ^c^& in the Replace With box to refer to the found text (the heading) followed by the contents of the clipboard (a section break).

Copying a section break is easier if you display non-breaking characters (¶)


.
*****
.
As computer scientists we are trained to communicate with the dumbest things in the world – computers –
so you’d think we’d be able to communicate quite well with people.
Prof. Doug Fisher

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Cool thank you so much, will try this. Will this work in MS Word 2013? We are using Word 2013

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

The following code will insert a landscape section in a document, adjusting the headers\footers to suit:

 

Sub Landscape()
Dim newSec As Section
Dim rngsel As Range
Dim secnum As Long
secnum = Selection.Information(wdActiveEndSectionNumber)
Selection.InsertBreak Type:=wdSectionBreakNextPage
Set newSec = Selection.Sections(1)
With newSec
    With .PageSetup
        .Orientation = wdOrientLandscape
        pw = .PageWidth
        .LeftMargin = CentimetersToPoints(2.5)
        .RightMargin = CentimetersToPoints(2.5)
        rt = pw - CentimetersToPoints(5)
        ct = rt / 2
        .DifferentFirstPageHeaderFooter = False
    End With
    For j = 1 To .Headers.Count
        With .Headers(j)
            .LinkToPrevious = False
            For i = 1 To .Range.Paragraphs.Count
                With .Range.Paragraphs(i).TabStops
                    .ClearAll
                    .Add rt, wdAlignTabRight
                End With
            Next i
            .PageNumbers.RestartNumberingAtSection = False
            If .Range.Tables.Count > 0 Then
                With .Range.Tables(1).Columns(1)
                    .Width = CentimetersToPoints(21.5)
                End With
            End If
        End With
    Next j
    For j = 1 To .Footers.Count
        With .Footers(j)
            .LinkToPrevious = False
            For i = 1 To .Range.Paragraphs.Count
                With .Range.Paragraphs(i).TabStops
                    .ClearAll
                    .Add ct, wdAlignTabCenter
                    .Add rt, wdAlignTabRight
                End With
            Next i
        End With
    Next j
End With
Portrait
Set rngsel = ActiveDocument.Sections(secnum + 1).Range
rngsel.Collapse wdCollapseStart
rngsel.Select
rngsel.InsertBefore vbCr
ActiveWindow.ScrollIntoView rngsel
End Sub


Sub Portrait()
Dim newSec As Section
Selection.InsertBreak Type:=wdSectionBreakNextPage
Set newSec = Selection.Sections(1)
With newSec
    With .PageSetup
        .Orientation = wdOrientPortrait
        pw = .PageWidth
        lm = .LeftMargin
        rm = .RightMargin
        rt = pw - lm - rm
        ct = rt / 2
        .DifferentFirstPageHeaderFooter = False
    End With
    For j = 1 To .Headers.Count
        With .Headers(j)
            .LinkToPrevious = False
            For i = 1 To .Range.Paragraphs.Count
                With .Range.Paragraphs(i).TabStops
                    .ClearAll
                    .Add rt, wdAlignTabRight
                End With
            Next i
            .PageNumbers.RestartNumberingAtSection = False
            If .Range.Tables.Count > 0 Then
                With .Range.Tables(1).Columns(1)
                    .Width = CentimetersToPoints(12)
                End With
            End If
        End With
    Next j
    For j = 1 To .Footers.Count
        With .Footers(j)
            .LinkToPrevious = False
            For i = 1 To .Range.Paragraphs.Count
                With .Range.Paragraphs(i).TabStops
                    .ClearAll
                    .Add ct, wdAlignTabCenter
                    .Add rt, wdAlignTabRight
                End With
            Next i
        End With
    Next j
End With
ActiveWindow.ScrollIntoView Selection.Range
End Sub

 

Running the Landscape macro will automatically create another portrait section to follow it.

 

It will work in 2007, 2010 and 2013.

 


Hope this helps,
Doug Robbins - MVP Office Apps & Services (Word)
dougrobbinsmvp@gmail.com
It's time to replace ‘Diversity, Equity & Inclusion’ with ‘Excellence, Opportunity & Civility’ - V Ramaswamy

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Thank you so much, I tried it out and it works well, when I press enter on the landscape page it does add another landscape page with its own header and footer and not a portrait page, and that is exactly what I wanted, but if I now need another landscape page after a portrait page do I every time have to go to Macros and run the macro so it can add a landscape page? Or is there an easier way to add a landscape page and a portrait page?

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Yes, you need to run the macro every time that you want to change from Portrait to Landscape.
Hope this helps,
Doug Robbins - MVP Office Apps & Services (Word)
dougrobbinsmvp@gmail.com
It's time to replace ‘Diversity, Equity & Inclusion’ with ‘Excellence, Opportunity & Civility’ - V Ramaswamy

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated March 16, 2022 Views 12,238 Applies to: