PDA

View Full Version : Solved: Bookmarks in the Header/Footer



village_alchemist
09-14-2004, 03:51 AM
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!

TonyJollans
09-14-2004, 09:17 AM
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 ..

ActiveDocument.StoryRanges(wdEvenPagesHeaderStory).Bookmarks("BookmarkName").Select

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.

village_alchemist
09-14-2004, 07:47 PM
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:

ActiveDocument.Bookmarks("hdrText").Select
Selection.TypeText sPhone
ActiveDocument.ActiveWindow.View = wdPrintView

Thanks for pointing me in the right direction (again)!