SonyaBlade44
Programmer
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:
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
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