Consulting

Results 1 to 3 of 3

Thread: Solved: Bookmarks in the Header/Footer

  1. #1
    VBAX Regular village_alchemist's Avatar
    Joined
    Jul 2004
    Location
    Michigan, US
    Posts
    32
    Location

    Solved: Bookmarks in the Header/Footer

    Is it possible to access a bookmark in the Header / Footer of a document through VBA? I've found it easy to add text to the beginning or end, but I couldn't figure it out using a bookmark.

    Thanks in advance!

  2. #2
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Documents are split into what Word calls StoryRanges. Processing storyranges other than the main body of the document in VBA can be a bit of a hit and miss affair, but if you know where your bookmarks are, something like this should work ..

    [VBA]ActiveDocument.StoryRanges(wdEvenPagesHeaderStory).Bookmarks("BookmarkName").Select[/VBA]

    if you can't make it function, or this doesn't fit the bill, post back with a few more details and I'll take a closer look.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  3. #3
    VBAX Regular village_alchemist's Avatar
    Joined
    Jul 2004
    Location
    Michigan, US
    Posts
    32
    Location
    Well, I've got good news, and I've got bad news...

    The bad news, Tony, is that I couldn't get your code snippit to work. Try as I might, it just refused to go to the bookmark before putting in the text.

    The good news is that you put me on the right track and with a little searching I found that in Word2000 and later you don't have to open the header or footer to access a bookmark. What it does do however, is put the document into "Normal" view (which, personally, I dislike - strongly). So after I insert the text, I changed the view back to "Print Layout". Here's the code I used assuming that there is a bookmark in the header called hdrText and a string variable called sPhone:
    [VBA]
    ActiveDocument.Bookmarks("hdrText").Select
    Selection.TypeText sPhone
    ActiveDocument.ActiveWindow.View = wdPrintView
    [/VBA]
    Thanks for pointing me in the right direction (again)!

Posting Permissions

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