Results 1 to 5 of 5
  1. #1
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Inserting Fields in Footer with VBA (Word2k, Access2k)

    I'm building a Word document from an Access database query using Automation, and all is going well, EXCEPT:
    I need to insert the Creation Date and Page M of N in the footer of the document - I could put it into a template and all is happy, but the users don't necessarily have access to the template. So I figured I would create it on the fly at the time it is initializing the document. The problem I am having is that everything I add to the footer overwrites the previous contents of the footer. A simplified version of the code is:
    <font face="Georgia">
    <font color=448800>' Insert the text string, then the date</font color=448800>
    With objWordDoc.Sections(1).Footers(wdHeaderFooterPrima ry).Range
    .Text = "Created on "
    .Font.Name = "Arial Narrow"
    .Font.Size = 8
    End With
    [objWordDoc.Sections(1).Footers(wdHeaderFooterPrima ry).Range.Collapse Direction:=wdCollapseEnd
    [objWordDoc.Fields.Add Range:=objWordDoc.Sections(1).Footers(wdHeaderFoot erPrimary).Range, _
    Type:=wdFieldEmpty, Text:="CREATEDATE ", PreserveFormatting:=True
    </font face=georgia>
    In particular, what appears not to work is the Range Collapse for the footer, as the Create Date simply overwrites the text string "Created On". Can someone suggest an approach that avoids this problem. TIA
    Wendell

  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: Inserting Fields in Footer with VBA (Word2k, Access2k)

    See if this approach works for you: Post #69614

  3. #3
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Inserting Fields in Footer with VBA (Word2k, Access2k)

    Thanks - I'll try it in the morning and see what happens. The whole thing with ranges (and not being able to use Selection) in the footer seems more than a little arcane.
    Wendell

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Inserting Fields in Footer with VBA (Word2k, Access2k)

    Wendell,

    You can use Selection to insert something into the footer, but to do so you need to go the correct footer and open it - it's doable but carries its own set of gotchas.

    Gary

  5. #5
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Inserting Fields in Footer with VBA (Word2k, Access2k)

    Thanks again - it works like a champ now. The code looks more than a little clumsy, but it works. My problem is understanding the difference between the .Range of a section and a range that I define myself, i.e. myRange. But I think I'm starting to get it.
    Wendell

Posting Permissions

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