• Insert Filename & path in footer (Eng (U.S.)/Word

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Insert Filename & path in footer (Eng (U.S.)/Word

    Author
    Topic
    #410196

    I have a macro that inserts the filepath in the footer in the right hand corner. However, if there is already something in the footer (e.g. page numbers), it pushes it off the page. How can I modify it so that it only inserts tabs if the footer is blank; & otherwise, insert the filepath in the lower right corner.
    Thanks in advance,

    Sub InsPath()
    '
    ' Macro modified 10/12/00 by Phil Rabichow
    '
    ' InsPath Macro
    ' Inserts complete filepath in footer, right justified, 8 pt, TNR
    '
    Dim UserView As Integer
    With ActiveWindow
        UserView = .View.Type
        If UserView  wdPageView Then
              .View.Type = wdPageView
        End If
        .ActivePane.View.SeekView = wdSeekCurrentPageHeader
        With Selection
            .MoveDown Unit:=wdLine, Count:=1
            .TypeText Text:=vbTab & vbTab
            .Fields.Add Range:=.Range, Type:=wdFieldEmpty, Text:= _
                "FILENAME p ", PreserveFormatting:=True
            .MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
            With .Font
                .Name = "Times New Roman"
                .Size = 8
                .Bold = False
            End With
        End With
        .ActivePane.View.SeekView = wdSeekMainDocument
        .View.Type = UserView
    End With
    End Sub
    Viewing 5 reply threads
    Author
    Replies
    • #879692

      (Edited by jscher2000 on 21-Sep-04 13:16. One other thought…)

      Before I read your post carefully, I was going to link to some previous posts on using range methods to insert stuff into footer. Oh what the heck, here they are:

      Re: Add Footer to Sections (Word 97) 30-Aug-01
      Re: Finding the page center (Word 2000) 13-May-02
      Re: working with ranges (WordXP) 29-Jul-03
      Footers (VBA) and Sections (XP) thread started 31-Jul-03

      I thought there was a property of a HeaderFooter object that tells you whether it is empty, but it seems that .Exists is not so powerful. One approach is illustrated in post 350847, but you also could do it with the selection object if you wished (e.g., equivalent of Ctrl+A in the footer).

      Added: If you use the Selection object, you can use the EndKey on the last line of the footer and then check the column number (as in the status bar) using Selection.Information(wdFirstCharacterColumnNumber) — 1 will indicate that there is nothing else on the line, a higher number will hint at what you have (e.g., 3 would hint at a tab followed by a page number field showing a single resulting digit). Still some guesswork involved, but perhaps a little bit more information than you can get with the range methods.

      • #880234

        Thanks for the links and thanks to all that responded. It’ll take me awhile to work my way through, but I’ll post back the results.

      • #880235

        Thanks for the links and thanks to all that responded. It’ll take me awhile to work my way through, but I’ll post back the results.

    • #879693

      (Edited by jscher2000 on 21-Sep-04 13:16. One other thought…)

      Before I read your post carefully, I was going to link to some previous posts on using range methods to insert stuff into footer. Oh what the heck, here they are:

      Re: Add Footer to Sections (Word 97) 30-Aug-01
      Re: Finding the page center (Word 2000) 13-May-02
      Re: working with ranges (WordXP) 29-Jul-03
      Footers (VBA) and Sections (XP) thread started 31-Jul-03

      I thought there was a property of a HeaderFooter object that tells you whether it is empty, but it seems that .Exists is not so powerful. One approach is illustrated in post 350847, but you also could do it with the selection object if you wished (e.g., equivalent of Ctrl+A in the footer).

      Added: If you use the Selection object, you can use the EndKey on the last line of the footer and then check the column number (as in the status bar) using Selection.Information(wdFirstCharacterColumnNumber) — 1 will indicate that there is nothing else on the line, a higher number will hint at what you have (e.g., 3 would hint at a tab followed by a page number field showing a single resulting digit). Still some guesswork involved, but perhaps a little bit more information than you can get with the range methods.

    • #879866

      Hi Phil,

      Another approach would be to create a textbox/frame in the right spot and put the filepath there. That way it’s independent of the contents and formatting of the footer.

    • #879867

      Hi Phil,

      Another approach would be to create a textbox/frame in the right spot and put the filepath there. That way it’s independent of the contents and formatting of the footer.

    • #879868

      Assuming I’m in the header (or footer), I check whether Selection.HeaderFooter.Range.Text = vbCr.

    • #879869

      Assuming I’m in the header (or footer), I check whether Selection.HeaderFooter.Range.Text = vbCr.

    Viewing 5 reply threads
    Reply To: Insert Filename & path in footer (Eng (U.S.)/Word

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: