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

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Using VBA to access bookmarks in the Header Area (Word 2000 VBA)

    Author
    Topic
    #367191

    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?

    Viewing 1 reply thread
    Author
    Replies
    • #571826

      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

    • #571849

      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

    Viewing 1 reply thread
    Reply To: Reply #571849 in Using VBA to access bookmarks in the Header Area (Word 2000 VBA)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel