Results 1 to 5 of 5
  1. #1
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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,<pre>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</pre>


  2. #2
    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: Insert Filename & path in footer (Eng (U.S.)/W

    <P ID="edit" class=small>(Edited by jscher2000 on 21-Sep-04 13:16. One other thought...)</P>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>post 350847</post#>, 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.

  3. #3
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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.

  4. #4
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

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

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

  5. #5
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Insert Filename & path in footer (Eng (U.S.)/W

    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.

Posting Permissions

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