Consulting

Results 1 to 13 of 13

Thread: Solved: Delete text in specific section's footer?

  1. #1
    VBAX Mentor clhare's Avatar
    Joined
    Mar 2005
    Posts
    470
    Location

    Solved: Delete text in specific section's footer?

    Is it possible to use a macro in Word that will go into the footer of a specific section and delete lines 2-4 of text in the first page footer only of that section?
    I need to be able to do this in sections 4 and 6 of my document and can't figure out how.

    Cheryl

  2. #2
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Yes.

    Say the footer in Section 4 First page is:

    Line 1
    Line 2
    Line 3
    Line 4

    [vba]Sub Section4Footer()
    Dim oRange As Word.Range
    Set oRange = _
    ActiveDocument.Sections(4).Footers(wdHeaderFooterFirstPage).Range
    oRange.Text = "New Line A" & vbCrLf & _
    "New line B" & vbCrLf & _
    "New line C" & vbCrLf & _
    "New line D"
    Set oRange = Nothing
    End Sub[/vba]

    will change it to Line A, Line B..... It does not affect any other footer.

  3. #3
    VBAX Mentor clhare's Avatar
    Joined
    Mar 2005
    Posts
    470
    Location
    What if I can't tell the macro the exact text in lines 2-4? I just know I want to delete whatever text in on those lines of that particular footer.

    Cheryl

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by clhare
    What if I can't tell the macro the exact text in lines 2-4? I just know I want to delete whatever text in on those lines of that particular footer.

    Cheryl
    Hi Cheryl,

    Something like:[vba]
    Sub Section4Footer()
    Dim oRange As Word.Range

    Set oRange = _
    ActiveDocument.Sections(4).Footers(wdHeaderFooterFirstPage).Range

    With oRange
    .Paragraphs(4).Range.Delete
    .Paragraphs(3).Range.Delete
    .Paragraphs(2).Range.Delete
    End With

    Set oRange = Nothing
    End Sub
    [/vba]

    Remember delete backwards (look at the numbering in my example) you are changing a collection over here!

    HTH,
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Please clarify and be specific in your requests.

    Do you want to delete the TEXT of each line, but KEEP the lines (ie. keep the paragraph marks)?

    Or do you want to delete everything?

    It is hard to tell from your post. Please note that Joost's code removes the paragraph. Actually, you should be able to figure this out from the original code.

    If you want to delete everything out of a specific footer:
    [vba] Dim oRange As Word.Range
    Set oRange = _
    ActiveDocument.Sections(4).Footers(wdHeaderFooterFirstPage).Range
    oRange.Delete
    Set oRange = Nothing[/vba]

    OR;

    oRange.Text = ""

    Please specify exactly what you want.

  6. #6
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Here is an alternative. It makes a range of the footer (First Page Section 4), moves the start until it finds a paragraph mark, moves one more character - to the start of the next line - then deletes the range. In other words, it deletes everything but the first paragraph.
    [vba]Dim oRange As Word.Range
    Set oRange = ActiveDocument.Sections(4). _
    Footers(wdHeaderFooterFirstPage).Range
    With oRange
    .MoveStartUntil cset:=Chr(13)
    .MoveEnd unit:=wdCharacter, Count:=1
    .Delete
    End With
    Set oRange = Nothing[/vba]

  7. #7
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Oh, and Joost...why declare oPara if you never use it?

  8. #8
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by fumei
    Oh, and Joost...why declare oPara if you never use it?
    No reason forgot to delete it!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  9. #9
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by fumei
    Please clarify and be specific in your requests.

    Do you want to delete the TEXT of each line, but KEEP the lines (ie. keep the paragraph marks)?
    Yes its a good idea to understand what Cheryl means with a "line". (But I'm sure there's stuff enough to be clear to a sollution)
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  10. #10
    VBAX Mentor clhare's Avatar
    Joined
    Mar 2005
    Posts
    470
    Location
    Joost's solution was exactly what I needed. I needed to delete the entire paragraph, not just the text.

    Thanks so much for your help!

  11. #11
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Sniff. Joost, Joost Joost...it's all about Joost. I think my code is better.

    .....you better think that is funny Joost...it is meant to be!

  12. #12
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by clhare
    Joost's solution was exactly what I needed. I needed to delete the entire paragraph, not just the text.

    Thanks so much for your help!
    Hi Cheryl,

    Glad your problems solved...you're welcome! (Ps don't forget my sollution was based on Gerry's code!)

    Later...
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  13. #13
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by fumei
    Sniff. Joost, Joost Joost...it's all about Joost. I think my code is better.

    .....you better think that is funny Joost...it is meant to be!
    Sure no problem!
    I have the same fealing Gerry, Gerry, Gerry...it's always GERRY!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •