Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bookmarks in Word's headers: Macro to place user's data

Status
Not open for further replies.

SonyaBlade44

Programmer
Feb 20, 2003
2
CA
Greetings Everyone,

I'm editing a Word template that runs a macro to gather user input. The original template used 'FILLIN' fields that would pop up individual boxes asking the user to enter information. The user would type in the answer, click ok, then another question box would appear and so on. That was annoying for my client. He wanted me to create something where a single form would appear, and he could tab to the next field or even skip some fields. That was the easy part.

I used Visual Basic for Applications in Word's macro area and created the form and fields with code. The information the user would enter was stored in variables until the OK button was clicked. Then, the macro would check through the entire document for the corresponding bookmarks for those user-entered values and insert the information. This worked perfectly until I got to the headers/footers.

In the Word document, I have bookmarks for the project title (bkProject), and client name (bkClientName). One bookmark is in the header, the other in the footer (that's what the client wants). If I add those bookmarks to the header/footer, I get this error message when the macro is run:

Microsoft Word Err=1582
Word cannot find the requested bookmark

It would seem that the search for bookmarks is limited to the main document area, excluding the header/footers. Is there a way that I can get the macro to look in and update bookmark locations for the header/footer in addition to the main document? I don't know what I would have to code to get inside those other sections.

The code I am using right now for the main document (that works) is as follows. There are more fields, but this is the general idea:


Code:
'Code to draw form with fields/labels
'Code to store user's entries in variables

Private Sub PutUserInput()
WordBasic.WW7_EditGoTo "bkClientName"
WordBasic.Insert vTxClientName$
WordBasic.StartOfLine 1
WordBasic.EditBookmark Name:="bkClientName", SortBy:=0, Add:=1

WordBasic.WW7_EditGoTo "bkProject"
WordBasic.Insert vTxProject$
WordBasic.StartOfLine 1
WordBasic.EditBookmark Name:="bkProject", SortBy:=0, Add:=1

WordBasic.WW7_EditGoTo "bkTitle"
WordBasic.Insert vTxTitle$
WordBasic.StartOfLine 1
WordBasic.EditBookmark Name:="bkTitle", SortBy:=0, Add:=1
' Many more bookmarks to update
End Sub

Without headers/footers, the above code works fine. It's only when I place the ClientName and Project bookmarks into the header/footer does a problem occur.

I've talked with my client and he absolutely has to have these items in the headers/footers. I'd really appreciate it if somebody could tell me how to accomplish this. All it has to do is look in the header/footer for the bookmarks and place the data.

Thanks for your time :)

Cassandra Singer
 
Cassandra,

The following code does not seem to have any trouble in identifying bookmarks in headers or footers...


ActiveDocument.Bookmarks("bmFooterAddress").Select
Selection.TypeText frmFax.txFooterAddress

"bmFooterAddress" is the bookmark on the document and 'frmFax.txFooterAddress' is a reference to the address entered in the form to capture the user entered data.

Hope this points you in the right direction.

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top