Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Mar 2001
    Location
    Austin, Texas, USA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    file name on last page macro (Word 97)

    I'm new at this, and can't for the life of me figure out what's wrong with the following macro... I want to put the file name in a footer, but only on the last page. Works beautifully, that is, until you print it... then the file name appears only on the first page.

    Public Sub FooterLastPage()
    Dim strFullName, strLibrary, strDocNum, strVersion, strNewPath, vFooterText As String
    Dim pos1, pos2, pos3 As Long
    Dim vFooterOn, vFound As Boolean

    strFullName = ActiveDocument.FullName

    'check to see if document is profiled, if not, exit
    If InStr(1, strFullName, "::ODMA", vbTextCompare) = 0 Then Exit Sub

    'if footer is on, toggle it off
    vFooterText = ActiveDocument.BuiltInDocumentProperties("Comments ").Value
    vFooterOn = (vFooterText <> "No Footer")
    If vFooterOn Then
    Call footertoggle
    End If

    'divide full path name into parts
    pos1 = InStr(InStr(1, strFullName, "", vbTextCompare) + 1, strFullName, "", vbTextCompare)
    pos2 = InStr(pos1 + 1, strFullName, "", vbTextCompare)
    pos3 = InStr(pos2 + 1, strFullName, "", vbTextCompare)
    strLibrary = Mid(strFullName, pos1 + 1, pos2 - (pos1 + 1))
    strDocNum = Mid(strFullName, pos2 + 1, pos3 - (pos2 + 1))
    strVersion = Mid(strFullName, pos3 + 1)

    'put the parts together in right configuration
    strNewPath = strLibrary & ":" & strDocNum & "." & strVersion

    ActiveDocument.Repaginate

    'go to last page footer and insert footer text as a field
    Selection.EndKey Unit:=wdStory
    ActiveWindow.View.SeekView = wdSeekCurrentPageFooter

    With Selection
    .Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, PreserveFormatting:=False
    .TypeText Text:="IF "
    .Fields.Add Range:=Selection.Range, Type:=wdFieldPage, PreserveFormatting:=False
    .MoveRight Unit:=wdCharacter, Count:=2
    .TypeText Text:=" = "
    .Fields.Add Range:=Selection.Range, Type:=wdFieldNumPages, PreserveFormatting:=False
    .MoveRight Unit:=wdCharacter, Count:=2
    .TypeText Text:=" "
    .Fields.Add Range:=Selection.Range, Type:=wdFieldQuote, PreserveFormatting:=False
    .TypeText Text:=strNewPath & " * MERGEFORMAT "
    .HomeKey
    .Fields.ToggleShowCodes
    .Fields.Update
    End With

    'exit footer
    ActiveWindow.View.SeekView = wdSeekMainDocument

    End Sub

    Thanks in advance!

    Susan

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: file name on last page macro (Word 97)

    Here's a tip that might help: footers are not stored on pages, but in sections. You need a new section at the end of your document. Put the footer in that section.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    New Lounger
    Join Date
    Mar 2001
    Location
    Austin, Texas, USA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: file name on last page macro (Word 97)

    Would it have to be a Next Page Section Break (with Same as Previous turned off)? Maybe there's no way to do what I'm trying to accomplish... I need the file name to appear on the last page of any existing document, regardless of how many section breaks there are (or whether or not they're formatted with "Same as Previous," etc.). I can't change any of the document formatting (so I can't add a Next Pg section break).

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: file name on last page macro (Word 97)

    You can do it with a trick discussed elsewhere on the lounge (Word forum, I think). You don't really need the section on the last page business either.

    Put a field code in your footer that conditionally displays the footer text if the current page is the last page. I'll post this now and look up the previous post and some code -- unless somebody beats me to it which is highly probable.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: file name on last page macro (Word 97)

    Here's the general idea:

    In your first page footer put this field code expression:

    { If { Page } = { Numpages } { FileName } "" }

    Make sure the Primary Foot is "Same as Previous" or put this expression in that foot as well.

    The only frustration is the field codes don't update dynamically. They will print just fine as long as you have that Update Fields setting in your Options checked.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  6. #6
    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: file name on last page macro (Word 97)

    This might be related to that terrible Page X of Y bug (Page 1 of 1, Page 2 of 2, etc.). Is your Word97 fully patched up? Apparently there was an SR-2 and a SR-3/Y2K fix. Somewhere in all that, the bug should have been fixed.

    On the field updates issue Kevin mentioned: according to the documentation, fields in headers and footers always update at print time; the checkbox governs whether the fields in the body are updated at print time.

    Lastly, if this approach doesn't work to your satisfaction, you could insert the footer in a frame on the last page of text.

  7. #7
    New Lounger
    Join Date
    Mar 2001
    Location
    Austin, Texas, USA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: file name on last page macro (Word 97)

    Yep, we're using SR2b.

    After playing around some more, I've fixed it by using a variation of Kevin's suggestion:
    { If { Page } = { Numpages } { FileName } "" }

    Thanks for the help!

    Susan

Posting Permissions

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