Results 1 to 12 of 12
  1. #1
    2 Star Lounger
    Join Date
    May 2006
    Location
    Portland, Oregon, USA
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Document Path in Footer (Word 2003)

    For years our templates have had the document path field in the footer. Consequently, we have MANY documents saved with the footer path in the footer. Now we are using Worldox document management. WD stamps the document ID in the footer. I'm trying to develope a macro to find the footer path and delete it, without deleting the entire footer. I'm pretty close, but I'm having trouble finding and selecting this type of field. Any Help?
    Thanks.
    Charlotte Quiroz

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Document Path in Footer (Word 2003)

    You could run the RemoveFilenameFields macro:

    Sub RemoveFilenameFields()
    Dim sec As Section
    Dim hfr As HeaderFooter
    For Each sec In ActiveDocument.Sections
    For Each hfr In sec.Headers
    RemoveFileNameFieldsFromHeaderFooter hfr
    Next hfr
    For Each hfr In sec.Footers
    RemoveFileNameFieldsFromHeaderFooter hfr
    Next hfr
    Next sec
    End Sub

    Sub RemoveFileNameFieldsFromHeaderFooter(hfr As HeaderFooter)
    Dim i As Integer
    If hfr.Exists Then
    If hfr.LinkToPrevious = False Or hfr.Parent.Index = 1 Then
    For i = hfr.Range.Fields.Count To 1 Step -1
    If hfr.Range.Fields(i).Type = wdFieldFileName Then
    hfr.Range.Fields(i).Delete
    End If
    Next i
    End If
    End If
    End Sub

  3. #3
    2 Star Lounger
    Join Date
    May 2006
    Location
    Portland, Oregon, USA
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Document Path in Footer (Word 2003)

    Thank you! It works like a charm!
    Charlotte Quiroz

  4. #4
    2 Star Lounger
    Join Date
    May 2006
    Location
    Portland, Oregon, USA
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Document Path in Footer (Word 2003)

    Hans: This works great IF the document path is in the footer, just as I told you. BUT, I'm discovering now that sometimes it is in the body of the document, at the end.
    Charlotte Quiroz

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Document Path in Footer (Word 2003)

    Here is an extension of the code that will handle the body of the document too:

    Sub RemoveFilenameFields()
    Dim sec As Section
    Dim hfr As HeaderFooter
    RemoveFileNameFieldsFromBody
    For Each sec In ActiveDocument.Sections
    For Each hfr In sec.Headers
    RemoveFileNameFieldsFromHeaderFooter hfr
    Next hfr
    For Each hfr In sec.Footers
    RemoveFileNameFieldsFromHeaderFooter hfr
    Next hfr
    Next sec
    End Sub

    Sub RemoveFileNameFieldsFromHeaderFooter(hfr As HeaderFooter)
    Dim i As Integer
    If hfr.Exists Then
    If hfr.LinkToPrevious = False Or hfr.Parent.Index = 1 Then
    For i = hfr.Range.Fields.Count To 1 Step -1
    If hfr.Range.Fields(i).Type = wdFieldFileName Then
    hfr.Range.Fields(i).Delete
    End If
    Next i
    End If
    End If
    End Sub

    Sub RemoveFileNameFieldsFromBody()
    Dim i As Integer
    For i = ActiveDocument.Fields.Count To 1 Step -1
    If ActiveDocument.Fields(i).Type = wdFieldFileName Then
    ActiveDocument.Fields(i).Delete
    End If
    Next i
    End Sub

  6. #6
    2 Star Lounger
    Join Date
    May 2006
    Location
    Portland, Oregon, USA
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Document Path in Footer (Word 2003)

    My gosh you're quick! Don't you ever sleep?
    This seems to do the trick. Thank you!
    Charlotte Quiroz

  7. #7
    2 Star Lounger
    Join Date
    May 2006
    Location
    Portland, Oregon, USA
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Document Path in Footer (Word 2003)

    Hans, I have one more for you. This one was actually given to me by the IT person of another firm (who also uses Worldox). Her footer is conditional. See Attached
    Attached Files Attached Files
    Charlotte Quiroz

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Document Path in Footer (Word 2003)

    The code that I posted will still remove the FILENAME field, even if it is part of an IF field. Do you want it to do something else instead?

  9. #9
    2 Star Lounger
    Join Date
    May 2006
    Location
    Portland, Oregon, USA
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Document Path in Footer (Word 2003)

    No, what I want to do is remove the field. When I run your code with this particular field, it is not being removed. When I stepped through the code,
    If ActiveDocument.Fields(i).Type = wdFieldFileName Then
    ActiveDocument.Fields(i).Delete
    End If
    The "IF" does not recognize that field as "wdFieldFileName". So, I changed that to wdFieldIf, without success.
    Charlotte Quiroz

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Document Path in Footer (Word 2003)

    Try this, but keep in mind that it will remove *all* IF fields from the document.
    <code>
    Sub RemoveFilenameFields()
    Dim sec As Section
    Dim hfr As HeaderFooter
    RemoveFileNameFieldsFromBody
    For Each sec In ActiveDocument.Sections
    For Each hfr In sec.Headers
    RemoveFileNameFieldsFromHeaderFooter hfr
    Next hfr
    For Each hfr In sec.Footers
    RemoveFileNameFieldsFromHeaderFooter hfr
    Next hfr
    Next sec
    End Sub

    Sub RemoveFileNameFieldsFromHeaderFooter(hfr As HeaderFooter)
    Dim i As Integer
    If hfr.Exists Then
    If hfr.LinkToPrevious = False Or hfr.Parent.Index = 1 Then
    For i = hfr.Range.Fields.Count To 1 Step -1
    If hfr.Range.Fields(i).Type = wdFieldFileName Or _
    hfr.Range.Fields(i).Type = wdFieldIf Then
    hfr.Range.Fields(i).Delete
    End If
    Next i
    End If
    End If
    End Sub

    Sub RemoveFileNameFieldsFromBody()
    Dim i As Integer
    For i = ActiveDocument.Fields.Count To 1 Step -1
    If ActiveDocument.Fields(i).Type = wdFieldFileName Or _
    ActiveDocument.Fields(i).Type = wdFieldIf Then
    ActiveDocument.Fields(i).Delete
    End If
    Next i
    End Sub</code>

  11. #11
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Document Path in Footer (Word 2003)

    You could peer inside the IF field for the string FILENAME as a way to roughly identify an IF field wrapped around a FILENAME field (air code):

    <code>If InStr(1,hfr.Range.Fields(i).Code.Text, "filename", vbTextCompare) > 0 Then hfr.Range.Fields(i).Delete</code>

    It's a little complicated looping and deleting with so many nested fields, but Word VBA doesn't seem to have very good tools for identifying only the "outer" fields.

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Document Path in Footer (Word 2003)

    Thanks!

Posting Permissions

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