Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Feb 2001
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using VBA to access bookmarks in the Header Area (Word 2000 VBA)

    Can anyone tell me how to use VBA to access bookmarks that are located in the header area. Or can you recommend another solution for inserting data collected from a user form into the header section?

  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: Using VBA to access bookmarks in the Header Area (Word 2000 VBA)

    By access, do you mean put data at the bookmark or retrieve text found there? Both?

    If you want to programmatically put text in a header you can use bookmarks, but document properties and document variables would be a better way to go.

    (In Word 97, document variables in a header of footer will crash Word, but Word 200x handles them fine.)

    Just put a reference to the doc var or doc prop in your header. Assign values to the doc var, for example, like this:

    Sub DocVarAssign(DocVar As String, ByVal DocValue As Variant)
    On Error Resume Next
    With ActiveDocument
    .Variables(DocVar).Delete
    .Variables.Add Name:=DocVar, Value:=DocValue
    End With
    End Sub
    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
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Using VBA to access bookmarks in the Header Area (Word 2000 VBA)

    If you do need to stick to bookmarks, then the code is simply:

    ActiveDocument.Bookmarks("bmkName").Range.Text = txtTextBox.Text

    - it doesn't matter if the bookmark is in the header or footer, the text will get inserted.

    Gary

Posting Permissions

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