×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How do I Remove Text from Even Page Header - Section 1 in a Word doc (2013) using VBA?

How do I Remove Text from Even Page Header - Section 1 in a Word doc (2013) using VBA?

How do I Remove Text from Even Page Header - Section 1 in a Word doc (2013) using VBA?

(OP)

History: I have a macro (not shown) that deletes the blank page that comes between the cover page and the proprietary page of a Word document that is generated from RoboHelp. However, the cover and the proprietary pages become the same section and the footer section (macro driven as well) is added to the cover. After, another round of coding and testing to address the footer appearing on the cover page (recall, after deleting the blank page), we found a way to delete the footer info, but it would have to be done for both the Cover page and the Proprietary page (have no issues with that). However, I have an issue that I need assitance on from one of the VBA gurus out there.

Problem: I need to remove the chapter name in the top-right hand corner (image link below).

Prior to the Word 2013 macros running, the chapter titles are listed in the header on every other page (even page has the name of the chapter in the document, e.g. Navigation). When running the macros, it removes the chapter names in the header, and does all the other custom formatting.

What I believe is happening: It is because we’re not processing the headers and footers in the first two sections (see red below in code excerpt). I think I might need to make an adjustment so that only the footer logic is skipped if the section index is less than or equal to 2. That way the headers should still be processed as necessary. So, how do I go about this?

I am guessing I will need to add some logic (within the existing code I have) that will look for ANY Text = “ ” only in Even Page Header - Section 1 and remove it ???

Thank you,
~PM

CODE:

Sub headerFooter()
Dim s As Section
For Each s In ActiveDocument.Sections
' Skip first two sections
If s.Index <= 2 Then GoTo NextSection

DoHeader s.Headers(wdHeaderFooterFirstPage)
DoFirstFooter s.Footers(wdHeaderFooterFirstPage)

DoHeader s.Headers(wdHeaderFooterPrimary)
DoOddFooter s.Footers(wdHeaderFooterPrimary)

DoHeader s.Headers(wdHeaderFooterEvenPages)
DoEvenFooter s.Footers(wdHeaderFooterEvenPages)
NextSection:
Next s
End Sub

RE: How do I Remove Text from Even Page Header - Section 1 in a Word doc (2013) using VBA?

As is apparent from your screenshot, your document has an even-pages header in Section 1. That's easily deleted via:
ActiveDocument.Sections(1).Headers(wdHeaderFooterEvenPages).Range.Text = vbNullString
If you need to preserve that header for subsequent Sections, precede that line with:
ActiveDocument.Sections(2).Headers(wdHeaderFooterEvenPages).LinkToPrevious = False

Cheers
Paul Edstein
[MS MVP - Word]

RE: How do I Remove Text from Even Page Header - Section 1 in a Word doc (2013) using VBA?

(OP)
Thank you Paul for your response and assistance. Your logic (code) worked. Just making sure that I placed the code in the appropriate spot (see below).

Thanks again,
~PM

Sub headerFooter()
Dim s As Section
For Each s In ActiveDocument.Sections
' Skip first two sections
If s.Index <= 2 Then GoTo NextSection
ActiveDocument.Sections(1).Headers(wdHeaderFooterEvenPages).Range.Text = vbNullString ' Delete text in even-pages header in Section 1
ActiveDocument.Sections(2).Headers(wdHeaderFooterEvenPages).LinkToPrevious = False ' To preserve header for subsequent Sections

DoHeader s.Headers(wdHeaderFooterFirstPage)
DoFirstFooter s.Footers(wdHeaderFooterFirstPage)

DoHeader s.Headers(wdHeaderFooterPrimary)
DoOddFooter s.Footers(wdHeaderFooterPrimary)

DoHeader s.Headers(wdHeaderFooterEvenPages)
DoEvenFooter s.Footers(wdHeaderFooterEvenPages)
NextSection:
Next s
End Sub

RE: How do I Remove Text from Even Page Header - Section 1 in a Word doc (2013) using VBA?

I can't see the point in putting the code I supplied inside a loop. A document can only contain one first section and, if there's more than one section, only one second section also. Moreover, your loop explicitly excludes the first two Sections so, if it only contains two sections, putting the code I provided inside your loop means it won't execute.

Cheers
Paul Edstein
[MS MVP - Word]

RE: How do I Remove Text from Even Page Header - Section 1 in a Word doc (2013) using VBA?

(OP)
Hi Paul,

I cleaned up the logic (see below), which works as well. Thnks, ~PM

Sub headerFooter()
Dim s As Section
For Each s In ActiveDocument.Sections
' Configure header on all but first section
If s.Index > 1 Then
DoHeader s.Headers(wdHeaderFooterFirstPage)
DoHeader s.Headers(wdHeaderFooterPrimary)
DoHeader s.Headers(wdHeaderFooterEvenPages)
End If

' Configure footer on all but first two sections
If s.Index > 2 Then
DoFirstFooter s.Footers(wdHeaderFooterFirstPage)
DoOddFooter s.Footers(wdHeaderFooterPrimary)
DoEvenFooter s.Footers(wdHeaderFooterEvenPages)
End If
Next
End Sub

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close