Home |
Search |
Today's Posts |
#1
|
|||
|
|||
MULTIPLE INSTANCES OF THE SAME BOOKMARK IN A USER FORM
I have a legal document that I am creating a user form for such that, when
the template is opened, a dialog box appears and the user can fill in the variables and then the document is populated with that information. I am using Bookmarks in this regard, however, one of the bookmarks appears in numerous places within the document and when I add the bookmark to the second place it disappears from the first place, etc. My question is how do I resolve this problem? Any help would be greatly appreciated. Thanks in advance. |
#2
|
|||
|
|||
On Mon, 28 Mar 2005 17:03:02 -0800, "Carol"
wrote: I have a legal document that I am creating a user form for such that, when the template is opened, a dialog box appears and the user can fill in the variables and then the document is populated with that information. I am using Bookmarks in this regard, however, one of the bookmarks appears in numerous places within the document and when I add the bookmark to the second place it disappears from the first place, etc. My question is how do I resolve this problem? Any help would be greatly appreciated. Thanks in advance. You can use any bookmark name only once per document, as you found out. In all the otoher places, insert REF fields (Insert Field, select REF from the list) that refer to the bookmark. The fields will repeat the contents of the bookmark. You'll need to update the fields after filling in the bookmark -- most easily by going to Print Preview and back. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
#3
|
|||
|
|||
Thanks for your help, but I guess I'm being obtuse. I have inserted fields
and selected Ref and selected the bookmark I want it to refer to but I'm still only getting the field showing. Is there perhaps another way of updating this template? Thanks again. "Jay Freedman" wrote: On Mon, 28 Mar 2005 17:03:02 -0800, "Carol" wrote: I have a legal document that I am creating a user form for such that, when the template is opened, a dialog box appears and the user can fill in the variables and then the document is populated with that information. I am using Bookmarks in this regard, however, one of the bookmarks appears in numerous places within the document and when I add the bookmark to the second place it disappears from the first place, etc. My question is how do I resolve this problem? Any help would be greatly appreciated. Thanks in advance. You can use any bookmark name only once per document, as you found out. In all the otoher places, insert REF fields (Insert Field, select REF from the list) that refer to the bookmark. The fields will repeat the contents of the bookmark. You'll need to update the fields after filling in the bookmark -- most easily by going to Print Preview and back. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
#4
|
|||
|
|||
If you mean that you're seeing something like
{ REF bookmarkname } in the document, press Alt+F9 to toggle from field codes to field results (or go to Tools Options View and uncheck "Field codes" which does the same thing). -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org On Tue, 29 Mar 2005 10:49:02 -0800, "Carol" wrote: Thanks for your help, but I guess I'm being obtuse. I have inserted fields and selected Ref and selected the bookmark I want it to refer to but I'm still only getting the field showing. Is there perhaps another way of updating this template? Thanks again. "Jay Freedman" wrote: On Mon, 28 Mar 2005 17:03:02 -0800, "Carol" wrote: I have a legal document that I am creating a user form for such that, when the template is opened, a dialog box appears and the user can fill in the variables and then the document is populated with that information. I am using Bookmarks in this regard, however, one of the bookmarks appears in numerous places within the document and when I add the bookmark to the second place it disappears from the first place, etc. My question is how do I resolve this problem? Any help would be greatly appreciated. Thanks in advance. You can use any bookmark name only once per document, as you found out. In all the otoher places, insert REF fields (Insert Field, select REF from the list) that refer to the bookmark. The fields will repeat the contents of the bookmark. You'll need to update the fields after filling in the bookmark -- most easily by going to Print Preview and back. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
#5
|
|||
|
|||
Hello Jay,
Yes, I did toggle the field codes and all it shows is the field code. When I use Alt +F9, it shows nothing else. I'm sure it's something very simple that I'm just not getting. Thanks for your help. "Jay Freedman" wrote: If you mean that you're seeing something like { REF bookmarkname } in the document, press Alt+F9 to toggle from field codes to field results (or go to Tools Options View and uncheck "Field codes" which does the same thing). -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org On Tue, 29 Mar 2005 10:49:02 -0800, "Carol" wrote: Thanks for your help, but I guess I'm being obtuse. I have inserted fields and selected Ref and selected the bookmark I want it to refer to but I'm still only getting the field showing. Is there perhaps another way of updating this template? Thanks again. "Jay Freedman" wrote: On Mon, 28 Mar 2005 17:03:02 -0800, "Carol" wrote: I have a legal document that I am creating a user form for such that, when the template is opened, a dialog box appears and the user can fill in the variables and then the document is populated with that information. I am using Bookmarks in this regard, however, one of the bookmarks appears in numerous places within the document and when I add the bookmark to the second place it disappears from the first place, etc. My question is how do I resolve this problem? Any help would be greatly appreciated. Thanks in advance. You can use any bookmark name only once per document, as you found out. In all the otoher places, insert REF fields (Insert Field, select REF from the list) that refer to the bookmark. The fields will repeat the contents of the bookmark. You'll need to update the fields after filling in the bookmark -- most easily by going to Print Preview and back. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
#6
|
|||
|
|||
Did you insert the braces using Ctrl+F9?
-- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Carol" wrote in message ... Hello Jay, Yes, I did toggle the field codes and all it shows is the field code. When I use Alt +F9, it shows nothing else. I'm sure it's something very simple that I'm just not getting. Thanks for your help. "Jay Freedman" wrote: If you mean that you're seeing something like { REF bookmarkname } in the document, press Alt+F9 to toggle from field codes to field results (or go to Tools Options View and uncheck "Field codes" which does the same thing). -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org On Tue, 29 Mar 2005 10:49:02 -0800, "Carol" wrote: Thanks for your help, but I guess I'm being obtuse. I have inserted fields and selected Ref and selected the bookmark I want it to refer to but I'm still only getting the field showing. Is there perhaps another way of updating this template? Thanks again. "Jay Freedman" wrote: On Mon, 28 Mar 2005 17:03:02 -0800, "Carol" wrote: I have a legal document that I am creating a user form for such that, when the template is opened, a dialog box appears and the user can fill in the variables and then the document is populated with that information. I am using Bookmarks in this regard, however, one of the bookmarks appears in numerous places within the document and when I add the bookmark to the second place it disappears from the first place, etc. My question is how do I resolve this problem? Any help would be greatly appreciated. Thanks in advance. You can use any bookmark name only once per document, as you found out. In all the otoher places, insert REF fields (Insert Field, select REF from the list) that refer to the bookmark. The fields will repeat the contents of the bookmark. You'll need to update the fields after filling in the bookmark -- most easily by going to Print Preview and back. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
#7
|
|||
|
|||
I have a legal document that I am using to teach myself how to create user
forms with dialog boxes to fill in the variables to populate the document. One of the variables is the word Decedent. This particular variable show up in multiple places in the document. For the first instance I add a bookmark and for all subsequent instances I click on Insert | Field and select ref and click on the bookmark that I want it to reference. I guess the part that I'm seemingly fouling up is this: Once I have done that in the template do I use Alt+F9 to update each time I create a reference or do I do that after I have completed the entire document? I am having several problems, but I would like to resolve this one first and then move on to the next step. I do appreciate all of your help. Thanks again. "Suzanne S. Barnhill" wrote: Did you insert the braces using Ctrl+F9? -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Carol" wrote in message ... Hello Jay, Yes, I did toggle the field codes and all it shows is the field code. When I use Alt +F9, it shows nothing else. I'm sure it's something very simple that I'm just not getting. Thanks for your help. "Jay Freedman" wrote: If you mean that you're seeing something like { REF bookmarkname } in the document, press Alt+F9 to toggle from field codes to field results (or go to Tools Options View and uncheck "Field codes" which does the same thing). -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org On Tue, 29 Mar 2005 10:49:02 -0800, "Carol" wrote: Thanks for your help, but I guess I'm being obtuse. I have inserted fields and selected Ref and selected the bookmark I want it to refer to but I'm still only getting the field showing. Is there perhaps another way of updating this template? Thanks again. "Jay Freedman" wrote: On Mon, 28 Mar 2005 17:03:02 -0800, "Carol" wrote: I have a legal document that I am creating a user form for such that, when the template is opened, a dialog box appears and the user can fill in the variables and then the document is populated with that information. I am using Bookmarks in this regard, however, one of the bookmarks appears in numerous places within the document and when I add the bookmark to the second place it disappears from the first place, etc. My question is how do I resolve this problem? Any help would be greatly appreciated. Thanks in advance. You can use any bookmark name only once per document, as you found out. In all the otoher places, insert REF fields (Insert Field, select REF from the list) that refer to the bookmark. The fields will repeat the contents of the bookmark. You'll need to update the fields after filling in the bookmark -- most easily by going to Print Preview and back. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
#8
|
|||
|
|||
You can insert the cross-references using Insert | Reference |
Cross-reference. You need to check the "Calculate on exit" box in the Form Field Options for the form field. When the document is protected, the cross-references will update automatically when the Decedent field is filled in. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Carol" wrote in message ... I have a legal document that I am using to teach myself how to create user forms with dialog boxes to fill in the variables to populate the document. One of the variables is the word Decedent. This particular variable show up in multiple places in the document. For the first instance I add a bookmark and for all subsequent instances I click on Insert | Field and select ref and click on the bookmark that I want it to reference. I guess the part that I'm seemingly fouling up is this: Once I have done that in the template do I use Alt+F9 to update each time I create a reference or do I do that after I have completed the entire document? I am having several problems, but I would like to resolve this one first and then move on to the next step. I do appreciate all of your help. Thanks again. "Suzanne S. Barnhill" wrote: Did you insert the braces using Ctrl+F9? -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Carol" wrote in message ... Hello Jay, Yes, I did toggle the field codes and all it shows is the field code. When I use Alt +F9, it shows nothing else. I'm sure it's something very simple that I'm just not getting. Thanks for your help. "Jay Freedman" wrote: If you mean that you're seeing something like { REF bookmarkname } in the document, press Alt+F9 to toggle from field codes to field results (or go to Tools Options View and uncheck "Field codes" which does the same thing). -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org On Tue, 29 Mar 2005 10:49:02 -0800, "Carol" wrote: Thanks for your help, but I guess I'm being obtuse. I have inserted fields and selected Ref and selected the bookmark I want it to refer to but I'm still only getting the field showing. Is there perhaps another way of updating this template? Thanks again. "Jay Freedman" wrote: On Mon, 28 Mar 2005 17:03:02 -0800, "Carol" wrote: I have a legal document that I am creating a user form for such that, when the template is opened, a dialog box appears and the user can fill in the variables and then the document is populated with that information. I am using Bookmarks in this regard, however, one of the bookmarks appears in numerous places within the document and when I add the bookmark to the second place it disappears from the first place, etc. My question is how do I resolve this problem? Any help would be greatly appreciated. Thanks in advance. You can use any bookmark name only once per document, as you found out. In all the otoher places, insert REF fields (Insert Field, select REF from the list) that refer to the bookmark. The fields will repeat the contents of the bookmark. You'll need to update the fields after filling in the bookmark -- most easily by going to Print Preview and back. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
#9
|
|||
|
|||
And to answer your question about Alt+F9:
- It's a toggle; every time you press Alt+F9, it either displays the field codes if the field results are showing, or it displays the field results if the field codes are showing. Press it twice and you're back where you started. - Alt+F9 by itself does not update the fields. That function is performed by F9 (without the Alt) for any fields that are currently selected; or by printing or going into Print Preview (assuming the "Update fields" option is checked in the Tools Options Print dialog); or, as Suzanne said, by having "Calculate on exit" checked for a form field in a protected form when that form field is the source for the Ref field. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org On Tue, 29 Mar 2005 22:59:28 -0600, "Suzanne S. Barnhill" wrote: You can insert the cross-references using Insert | Reference | Cross-reference. You need to check the "Calculate on exit" box in the Form Field Options for the form field. When the document is protected, the cross-references will update automatically when the Decedent field is filled in. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Carol" wrote in message ... I have a legal document that I am using to teach myself how to create user forms with dialog boxes to fill in the variables to populate the document. One of the variables is the word Decedent. This particular variable show up in multiple places in the document. For the first instance I add a bookmark and for all subsequent instances I click on Insert | Field and select ref and click on the bookmark that I want it to reference. I guess the part that I'm seemingly fouling up is this: Once I have done that in the template do I use Alt+F9 to update each time I create a reference or do I do that after I have completed the entire document? I am having several problems, but I would like to resolve this one first and then move on to the next step. I do appreciate all of your help. Thanks again. "Suzanne S. Barnhill" wrote: Did you insert the braces using Ctrl+F9? -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Carol" wrote in message ... Hello Jay, Yes, I did toggle the field codes and all it shows is the field code. When I use Alt +F9, it shows nothing else. I'm sure it's something very simple that I'm just not getting. Thanks for your help. "Jay Freedman" wrote: If you mean that you're seeing something like { REF bookmarkname } in the document, press Alt+F9 to toggle from field codes to field results (or go to Tools Options View and uncheck "Field codes" which does the same thing). -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org On Tue, 29 Mar 2005 10:49:02 -0800, "Carol" wrote: Thanks for your help, but I guess I'm being obtuse. I have inserted fields and selected Ref and selected the bookmark I want it to refer to but I'm still only getting the field showing. Is there perhaps another way of updating this template? Thanks again. "Jay Freedman" wrote: On Mon, 28 Mar 2005 17:03:02 -0800, "Carol" wrote: I have a legal document that I am creating a user form for such that, when the template is opened, a dialog box appears and the user can fill in the variables and then the document is populated with that information. I am using Bookmarks in this regard, however, one of the bookmarks appears in numerous places within the document and when I add the bookmark to the second place it disappears from the first place, etc. My question is how do I resolve this problem? Any help would be greatly appreciated. Thanks in advance. You can use any bookmark name only once per document, as you found out. In all the otoher places, insert REF fields (Insert Field, select REF from the list) that refer to the bookmark. The fields will repeat the contents of the bookmark. You'll need to update the fields after filling in the bookmark -- most easily by going to Print Preview and back. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
#10
|
|||
|
|||
Thanks for all the input. This is not a protected form but, rather, a
template that I am configuring so that when it is selected, a dialog box (user form) will pop up to fill in the variables needed for the document to be complete. I am going start over from scratch today and will report on my success/failure. Thanks again! "Jay Freedman" wrote: And to answer your question about Alt+F9: - It's a toggle; every time you press Alt+F9, it either displays the field codes if the field results are showing, or it displays the field results if the field codes are showing. Press it twice and you're back where you started. - Alt+F9 by itself does not update the fields. That function is performed by F9 (without the Alt) for any fields that are currently selected; or by printing or going into Print Preview (assuming the "Update fields" option is checked in the Tools Options Print dialog); or, as Suzanne said, by having "Calculate on exit" checked for a form field in a protected form when that form field is the source for the Ref field. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org On Tue, 29 Mar 2005 22:59:28 -0600, "Suzanne S. Barnhill" wrote: You can insert the cross-references using Insert | Reference | Cross-reference. You need to check the "Calculate on exit" box in the Form Field Options for the form field. When the document is protected, the cross-references will update automatically when the Decedent field is filled in. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Carol" wrote in message ... I have a legal document that I am using to teach myself how to create user forms with dialog boxes to fill in the variables to populate the document. One of the variables is the word Decedent. This particular variable show up in multiple places in the document. For the first instance I add a bookmark and for all subsequent instances I click on Insert | Field and select ref and click on the bookmark that I want it to reference. I guess the part that I'm seemingly fouling up is this: Once I have done that in the template do I use Alt+F9 to update each time I create a reference or do I do that after I have completed the entire document? I am having several problems, but I would like to resolve this one first and then move on to the next step. I do appreciate all of your help. Thanks again. "Suzanne S. Barnhill" wrote: Did you insert the braces using Ctrl+F9? -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Carol" wrote in message ... Hello Jay, Yes, I did toggle the field codes and all it shows is the field code. When I use Alt +F9, it shows nothing else. I'm sure it's something very simple that I'm just not getting. Thanks for your help. "Jay Freedman" wrote: If you mean that you're seeing something like { REF bookmarkname } in the document, press Alt+F9 to toggle from field codes to field results (or go to Tools Options View and uncheck "Field codes" which does the same thing). -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org On Tue, 29 Mar 2005 10:49:02 -0800, "Carol" wrote: Thanks for your help, but I guess I'm being obtuse. I have inserted fields and selected Ref and selected the bookmark I want it to refer to but I'm still only getting the field showing. Is there perhaps another way of updating this template? Thanks again. "Jay Freedman" wrote: On Mon, 28 Mar 2005 17:03:02 -0800, "Carol" wrote: I have a legal document that I am creating a user form for such that, when the template is opened, a dialog box appears and the user can fill in the variables and then the document is populated with that information. I am using Bookmarks in this regard, however, one of the bookmarks appears in numerous places within the document and when I add the bookmark to the second place it disappears from the first place, etc. My question is how do I resolve this problem? Any help would be greatly appreciated. Thanks in advance. You can use any bookmark name only once per document, as you found out. In all the otoher places, insert REF fields (Insert Field, select REF from the list) that refer to the bookmark. The fields will repeat the contents of the bookmark. You'll need to update the fields after filling in the bookmark -- most easily by going to Print Preview and back. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
#11
|
|||
|
|||
I started from scratch with the document. In the spots where I wanted the
different variables, I clicked on Insert | Bookmark and then typed in the name and clicked on Add. Where a variable was used more than once I clicked on Insert | Fields and Ref and clicked ont he Bookmark that it pointed to. Then I went to the Visual Basic Editor and inserted the User Form and added labels and textboxes for all of the bookmarks. I then added a command button and named it ok. After that I right-clicked on the command button and chose View Code. Once there, in between "Private Sub CommandButton1_Click()" and "End Sub," I typed: With ActiveDocument ..Bookmarks("Decedent").Range _ ..InsertBefore TextBox1 ..Bookmarks("Venue").Range _ ..InsertBefore TextBox2 ..Bookmarks("Estate Number").Range _ InsertBefore TextBox3 ..Bookmarks("Personal Representative").Range _ ..InsertBefore TextBox4 ..Bookmarks(Date of Death").Range _ ..InsertBefore TextBox5 End With Userform1.Hide Ok, then I used Alt+Q to go back to Word and I saved the template and then I created a macro in that template called AutoNew which essentially said UserForm1.Show. So then I saved it and closed it and went to File, New, From my Computer and selected it and the dialog box popped up and I filled in all the variables and clicked on the button and it just keeps telling me "Runtime error 5941. Teh requested member of the collection does not exist. I have to tell you - it's making me crazy! Any suggestions you might have would be extremely welcome at this point. Thanks again. "Carol" wrote: Thanks for all the input. This is not a protected form but, rather, a template that I am configuring so that when it is selected, a dialog box (user form) will pop up to fill in the variables needed for the document to be complete. I am going start over from scratch today and will report on my success/failure. Thanks again! "Jay Freedman" wrote: And to answer your question about Alt+F9: - It's a toggle; every time you press Alt+F9, it either displays the field codes if the field results are showing, or it displays the field results if the field codes are showing. Press it twice and you're back where you started. - Alt+F9 by itself does not update the fields. That function is performed by F9 (without the Alt) for any fields that are currently selected; or by printing or going into Print Preview (assuming the "Update fields" option is checked in the Tools Options Print dialog); or, as Suzanne said, by having "Calculate on exit" checked for a form field in a protected form when that form field is the source for the Ref field. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org On Tue, 29 Mar 2005 22:59:28 -0600, "Suzanne S. Barnhill" wrote: You can insert the cross-references using Insert | Reference | Cross-reference. You need to check the "Calculate on exit" box in the Form Field Options for the form field. When the document is protected, the cross-references will update automatically when the Decedent field is filled in. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Carol" wrote in message ... I have a legal document that I am using to teach myself how to create user forms with dialog boxes to fill in the variables to populate the document. One of the variables is the word Decedent. This particular variable show up in multiple places in the document. For the first instance I add a bookmark and for all subsequent instances I click on Insert | Field and select ref and click on the bookmark that I want it to reference. I guess the part that I'm seemingly fouling up is this: Once I have done that in the template do I use Alt+F9 to update each time I create a reference or do I do that after I have completed the entire document? I am having several problems, but I would like to resolve this one first and then move on to the next step. I do appreciate all of your help. Thanks again. "Suzanne S. Barnhill" wrote: Did you insert the braces using Ctrl+F9? -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Carol" wrote in message ... Hello Jay, Yes, I did toggle the field codes and all it shows is the field code. When I use Alt +F9, it shows nothing else. I'm sure it's something very simple that I'm just not getting. Thanks for your help. "Jay Freedman" wrote: If you mean that you're seeing something like { REF bookmarkname } in the document, press Alt+F9 to toggle from field codes to field results (or go to Tools Options View and uncheck "Field codes" which does the same thing). -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org On Tue, 29 Mar 2005 10:49:02 -0800, "Carol" wrote: Thanks for your help, but I guess I'm being obtuse. I have inserted fields and selected Ref and selected the bookmark I want it to refer to but I'm still only getting the field showing. Is there perhaps another way of updating this template? Thanks again. "Jay Freedman" wrote: On Mon, 28 Mar 2005 17:03:02 -0800, "Carol" wrote: I have a legal document that I am creating a user form for such that, when the template is opened, a dialog box appears and the user can fill in the variables and then the document is populated with that information. I am using Bookmarks in this regard, however, one of the bookmarks appears in numerous places within the document and when I add the bookmark to the second place it disappears from the first place, etc. My question is how do I resolve this problem? Any help would be greatly appreciated. Thanks in advance. You can use any bookmark name only once per document, as you found out. In all the otoher places, insert REF fields (Insert Field, select REF from the list) that refer to the bookmark. The fields will repeat the contents of the bookmark. You'll need to update the fields after filling in the bookmark -- most easily by going to Print Preview and back. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
#12
|
|||
|
|||
Hi Carol,
You're getting there... but you have to exactly match the names of the bookmarks in the code. Since spaces aren't legal in bookmark names, I can tell right away some of them are wrong. Look at the names in the list when you bring up the Insert Bookmark dialog, and make the names in the code *exactly* the same. There's another complication with the way you userform is putting the text in the document. When you use the .InsertBefore command, the text goes *before* the bookmark, not *in* the bookmark. So when you do get the userform to finish without errors, the Ref fields won't have anything to show because the bookmarks themselves will be empty. The proper code for this is shown he http://word.mvps.org/FAQs/MacrosVBA/...AtBookmark.htm -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Carol wrote: I started from scratch with the document. In the spots where I wanted the different variables, I clicked on Insert | Bookmark and then typed in the name and clicked on Add. Where a variable was used more than once I clicked on Insert | Fields and Ref and clicked ont he Bookmark that it pointed to. Then I went to the Visual Basic Editor and inserted the User Form and added labels and textboxes for all of the bookmarks. I then added a command button and named it ok. After that I right-clicked on the command button and chose View Code. Once there, in between "Private Sub CommandButton1_Click()" and "End Sub," I typed: With ActiveDocument .Bookmarks("Decedent").Range _ .InsertBefore TextBox1 .Bookmarks("Venue").Range _ .InsertBefore TextBox2 .Bookmarks("Estate Number").Range _ InsertBefore TextBox3 .Bookmarks("Personal Representative").Range _ .InsertBefore TextBox4 .Bookmarks(Date of Death").Range _ .InsertBefore TextBox5 End With Userform1.Hide Ok, then I used Alt+Q to go back to Word and I saved the template and then I created a macro in that template called AutoNew which essentially said UserForm1.Show. So then I saved it and closed it and went to File, New, From my Computer and selected it and the dialog box popped up and I filled in all the variables and clicked on the button and it just keeps telling me "Runtime error 5941. Teh requested member of the collection does not exist. I have to tell you - it's making me crazy! Any suggestions you might have would be extremely welcome at this point. Thanks again. "Carol" wrote: Thanks for all the input. This is not a protected form but, rather, a template that I am configuring so that when it is selected, a dialog box (user form) will pop up to fill in the variables needed for the document to be complete. I am going start over from scratch today and will report on my success/failure. Thanks again! "Jay Freedman" wrote: And to answer your question about Alt+F9: - It's a toggle; every time you press Alt+F9, it either displays the field codes if the field results are showing, or it displays the field results if the field codes are showing. Press it twice and you're back where you started. - Alt+F9 by itself does not update the fields. That function is performed by F9 (without the Alt) for any fields that are currently selected; or by printing or going into Print Preview (assuming the "Update fields" option is checked in the Tools Options Print dialog); or, as Suzanne said, by having "Calculate on exit" checked for a form field in a protected form when that form field is the source for the Ref field. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org On Tue, 29 Mar 2005 22:59:28 -0600, "Suzanne S. Barnhill" wrote: You can insert the cross-references using Insert | Reference | Cross-reference. You need to check the "Calculate on exit" box in the Form Field Options for the form field. When the document is protected, the cross-references will update automatically when the Decedent field is filled in. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Carol" wrote in message ... I have a legal document that I am using to teach myself how to create user forms with dialog boxes to fill in the variables to populate the document. One of the variables is the word Decedent. This particular variable show up in multiple places in the document. For the first instance I add a bookmark and for all subsequent instances I click on Insert | Field and select ref and click on the bookmark that I want it to reference. I guess the part that I'm seemingly fouling up is this: Once I have done that in the template do I use Alt+F9 to update each time I create a reference or do I do that after I have completed the entire document? I am having several problems, but I would like to resolve this one first and then move on to the next step. I do appreciate all of your help. Thanks again. "Suzanne S. Barnhill" wrote: Did you insert the braces using Ctrl+F9? -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Carol" wrote in message ... Hello Jay, Yes, I did toggle the field codes and all it shows is the field code. When I use Alt +F9, it shows nothing else. I'm sure it's something very simple that I'm just not getting. Thanks for your help. "Jay Freedman" wrote: If you mean that you're seeing something like { REF bookmarkname } in the document, press Alt+F9 to toggle from field codes to field results (or go to Tools Options View and uncheck "Field codes" which does the same thing). -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org On Tue, 29 Mar 2005 10:49:02 -0800, "Carol" wrote: Thanks for your help, but I guess I'm being obtuse. I have inserted fields and selected Ref and selected the bookmark I want it to refer to but I'm still only getting the field showing. Is there perhaps another way of updating this template? Thanks again. "Jay Freedman" wrote: On Mon, 28 Mar 2005 17:03:02 -0800, "Carol" wrote: I have a legal document that I am creating a user form for such that, when the template is opened, a dialog box appears and the user can fill in the variables and then the document is populated with that information. I am using Bookmarks in this regard, however, one of the bookmarks appears in numerous places within the document and when I add the bookmark to the second place it disappears from the first place, etc. My question is how do I resolve this problem? Any help would be greatly appreciated. Thanks in advance. You can use any bookmark name only once per document, as you found out. In all the otoher places, insert REF fields (Insert Field, select REF from the list) that refer to the bookmark. The fields will repeat the contents of the bookmark. You'll need to update the fields after filling in the bookmark -- most easily by going to Print Preview and back. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
#13
|
|||
|
|||
Hi Jay,
I stepped through the code and had just about decided that the problem was just what you said because the error popped up at the two separate words. So now I have fixed the bookmarks and the code so that they are the same and they do indeed fall in right where they should, but the ref fields are not working and as you have seen, I am very new to this aspect of word, and even after reading the article that you sent to me, I am still very unsure as to how I should write the code for the ref fields. I guess the problem is that I don't understand how using InsertBefore only screws up the ref fields and not the actual bookmarks. Also, reading the article is a bit difficult for me because I don't understand what Dim BMRange means. Are there any articles or tutorials that can help me with this? Or could you tell me how to do one so that I can go from there? I so appreciate your's and Suzanne's help! "Jay Freedman" wrote: Hi Carol, You're getting there... but you have to exactly match the names of the bookmarks in the code. Since spaces aren't legal in bookmark names, I can tell right away some of them are wrong. Look at the names in the list when you bring up the Insert Bookmark dialog, and make the names in the code *exactly* the same. There's another complication with the way you userform is putting the text in the document. When you use the .InsertBefore command, the text goes *before* the bookmark, not *in* the bookmark. So when you do get the userform to finish without errors, the Ref fields won't have anything to show because the bookmarks themselves will be empty. The proper code for this is shown he http://word.mvps.org/FAQs/MacrosVBA/...AtBookmark.htm -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Carol wrote: I started from scratch with the document. In the spots where I wanted the different variables, I clicked on Insert | Bookmark and then typed in the name and clicked on Add. Where a variable was used more than once I clicked on Insert | Fields and Ref and clicked ont he Bookmark that it pointed to. Then I went to the Visual Basic Editor and inserted the User Form and added labels and textboxes for all of the bookmarks. I then added a command button and named it ok. After that I right-clicked on the command button and chose View Code. Once there, in between "Private Sub CommandButton1_Click()" and "End Sub," I typed: With ActiveDocument .Bookmarks("Decedent").Range _ .InsertBefore TextBox1 .Bookmarks("Venue").Range _ .InsertBefore TextBox2 .Bookmarks("Estate Number").Range _ InsertBefore TextBox3 .Bookmarks("Personal Representative").Range _ .InsertBefore TextBox4 .Bookmarks(Date of Death").Range _ .InsertBefore TextBox5 End With Userform1.Hide Ok, then I used Alt+Q to go back to Word and I saved the template and then I created a macro in that template called AutoNew which essentially said UserForm1.Show. So then I saved it and closed it and went to File, New, From my Computer and selected it and the dialog box popped up and I filled in all the variables and clicked on the button and it just keeps telling me "Runtime error 5941. Teh requested member of the collection does not exist. I have to tell you - it's making me crazy! Any suggestions you might have would be extremely welcome at this point. Thanks again. "Carol" wrote: Thanks for all the input. This is not a protected form but, rather, a template that I am configuring so that when it is selected, a dialog box (user form) will pop up to fill in the variables needed for the document to be complete. I am going start over from scratch today and will report on my success/failure. Thanks again! "Jay Freedman" wrote: And to answer your question about Alt+F9: - It's a toggle; every time you press Alt+F9, it either displays the field codes if the field results are showing, or it displays the field results if the field codes are showing. Press it twice and you're back where you started. - Alt+F9 by itself does not update the fields. That function is performed by F9 (without the Alt) for any fields that are currently selected; or by printing or going into Print Preview (assuming the "Update fields" option is checked in the Tools Options Print dialog); or, as Suzanne said, by having "Calculate on exit" checked for a form field in a protected form when that form field is the source for the Ref field. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org On Tue, 29 Mar 2005 22:59:28 -0600, "Suzanne S. Barnhill" wrote: You can insert the cross-references using Insert | Reference | Cross-reference. You need to check the "Calculate on exit" box in the Form Field Options for the form field. When the document is protected, the cross-references will update automatically when the Decedent field is filled in. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Carol" wrote in message ... I have a legal document that I am using to teach myself how to create user forms with dialog boxes to fill in the variables to populate the document. One of the variables is the word Decedent. This particular variable show up in multiple places in the document. For the first instance I add a bookmark and for all subsequent instances I click on Insert | Field and select ref and click on the bookmark that I want it to reference. I guess the part that I'm seemingly fouling up is this: Once I have done that in the template do I use Alt+F9 to update each time I create a reference or do I do that after I have completed the entire document? I am having several problems, but I would like to resolve this one first and then move on to the next step. I do appreciate all of your help. Thanks again. "Suzanne S. Barnhill" wrote: Did you insert the braces using Ctrl+F9? -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "Carol" wrote in message ... Hello Jay, Yes, I did toggle the field codes and all it shows is the field code. When I use Alt +F9, it shows nothing else. I'm sure it's something very simple that I'm just not getting. Thanks for your help. "Jay Freedman" wrote: If you mean that you're seeing something like { REF bookmarkname } in the document, press Alt+F9 to toggle from field codes to field results (or go to Tools Options View and uncheck "Field codes" which does the same thing). -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org On Tue, 29 Mar 2005 10:49:02 -0800, "Carol" wrote: Thanks for your help, but I guess I'm being obtuse. I have inserted fields and selected Ref and selected the bookmark I want it to refer to but I'm still only getting the field showing. Is there perhaps another way of updating this template? Thanks again. "Jay Freedman" wrote: On Mon, 28 Mar 2005 17:03:02 -0800, "Carol" wrote: I have a legal document that I am creating a user form for such that, when the template is opened, a dialog box appears and the user can fill in the variables and then the document is populated with that information. I am using Bookmarks in this regard, however, one of the bookmarks appears in numerous places within the document and when I add the bookmark to the second place it disappears from the first place, etc. My question is how do I resolve this problem? Any help would be greatly appreciated. Thanks in advance. You can use any bookmark name only once per document, as you found out. In all the otoher places, insert REF fields (Insert Field, select REF from the list) that refer to the bookmark. The fields will repeat the contents of the bookmark. You'll need to update the fields after filling in the bookmark -- most easily by going to Print Preview and back. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
#14
|
|||
|
|||
Hi Carol,
There are a lot of interrelated things going on in your document and its code, and it's a hard to cover them all at one go. Still, let's try to cover them one at at time. 1. A bookmark is just a name for a location in the document. It doesn't have any active properties -- it can't make things happen. Fields like the Ref field can do things, and macros/userforms are all about doing things, but bookmarks just lie there. Think of bookmarks and text as nouns, and macros/userforms and some fields as verbs. So the userform code uses the bookmark as a location to stuff some text into the document. Other than the text appearing there, *nothing* happens. The Ref fields don't find out about the new text unless you somehow tell them to update themselves (here, "update" means "make a copy of the bookmark's contents and display that copy at the Ref field's location"). A few responses ago, I said that F9 updates fields, and so does printing or going to Print Preview. One other thing that can cause an update is to put this line of code in your userform's CommandButton1_Click() procedure, just before the Hide statement: ActiveDocument.Fields.Update [Everything in Word is complicated. In this case, the complication is that the line of code only updates fields in the body of the document, not in headers, footers, or textboxes. I'll assume for now that this doesn't make any difference in your document.] 2. Now we come to the difference between using the .InsertBefore method and using the approach in the article I recommended. This is completely unintuitive, even to me. As I said, a bookmark is just a named location in the text. It can cover one or more characters, or it can be collapsed to a single point between characters, and it behaves differently depending on which it is. If the bookmark is collapsed to a point (because you had nothing selected when you created it), then the .InsertBefore method will insert new text *after* the bookmark, *outside* it. (I think this behavior is a VBA bug -- the new text should go before the bookmark.) The bookmark will remain empty. If a Ref field points to that bookmark, then updating the field will cause it to display nothing -- because that's what's inside the bookmark, nothing. If the bookmark covers one or more characters (which could be spaces), then the .InsertBefore method inserts the new text inside the bookmark before the existing contents. This is the only case in which it does what you expect. Afterward, updating the Ref field that points to the bookmark will show a copy of the bookmark's contents, including both the new text and the old contents. This works ok as long as you only insert new text once. Try it again and you get *both* sets of text in the bookmark, and *both* sets reflected in the Ref field. The method shown in the InsertingTextAtBookmark.htm article -- assigning the new text to the range of the bookmark, and then re-inserting the bookmark to cover the inserted text -- gives you exactly what you need, predictably and with the ability to use the same bookmark again. 3. The expression "Dim BMRange As Range" tells VBA that you're going to use a variable named BMRange, and that it's going to represent a range -- that is, a particular piece of the document. (The "Dim" is short for "Dimension" and is a leftover from much older programming languages.) After that, the statement that begins with "Set BMRange =" finds the range that corresponds to the named bookmark, and assigns that range to the variable BMRange. That way you'll be able to use the variable to re-insert the bookmark later. The code you showed earlier needs to be rewritten like this. Notice that the variable BMRange can be re-used to point to different ranges at different times during the execution of the code. Private Sub CommandButton1_Click() Dim BMRange As Range With ActiveDocument Set BMRange = .Bookmarks("Decedent").Range BMRange.Text = TextBox1 .Bookmarks.Add "Decedent", BMRange Set BMRange = .Bookmarks("Venue").Range BMRange.Text = TextBox2 .Bookmarks.Add "Venue", BMRange Set BMRange = .Bookmarks("EstateNumber").Range BMRange.Text = TextBox3 .Bookmarks.Add "EstateNumber", BMRange Set BMRange = .Bookmarks("PersonalRepresentative").Range BMRange.Text = TextBox4 .Bookmarks.Add "PersonalRepresentative", BMRange Set BMRange = .Bookmarks("DateOfDeath").Range BMRange.Text = TextBox5 .Bookmarks.Add "DateOfDeath", BMRange End With ActiveDocument.Fields.Update UserForm1.Hide End Sub -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org On Wed, 30 Mar 2005 15:19:05 -0800, "Carol" wrote: Hi Jay, I stepped through the code and had just about decided that the problem was just what you said because the error popped up at the two separate words. So now I have fixed the bookmarks and the code so that they are the same and they do indeed fall in right where they should, but the ref fields are not working and as you have seen, I am very new to this aspect of word, and even after reading the article that you sent to me, I am still very unsure as to how I should write the code for the ref fields. I guess the problem is that I don't understand how using InsertBefore only screws up the ref fields and not the actual bookmarks. Also, reading the article is a bit difficult for me because I don't understand what Dim BMRange means. Are there any articles or tutorials that can help me with this? Or could you tell me how to do one so that I can go from there? I so appreciate your's and Suzanne's help! "Jay Freedman" wrote: Hi Carol, You're getting there... but you have to exactly match the names of the bookmarks in the code. Since spaces aren't legal in bookmark names, I can tell right away some of them are wrong. Look at the names in the list when you bring up the Insert Bookmark dialog, and make the names in the code *exactly* the same. There's another complication with the way you userform is putting the text in the document. When you use the .InsertBefore command, the text goes *before* the bookmark, not *in* the bookmark. So when you do get the userform to finish without errors, the Ref fields won't have anything to show because the bookmarks themselves will be empty. The proper code for this is shown he http://word.mvps.org/FAQs/MacrosVBA/...AtBookmark.htm -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Carol wrote: I started from scratch with the document. In the spots where I wanted the different variables, I clicked on Insert | Bookmark and then typed in the name and clicked on Add. Where a variable was used more than once I clicked on Insert | Fields and Ref and clicked ont he Bookmark that it pointed to. Then I went to the Visual Basic Editor and inserted the User Form and added labels and textboxes for all of the bookmarks. I then added a command button and named it ok. After that I right-clicked on the command button and chose View Code. Once there, in between "Private Sub CommandButton1_Click()" and "End Sub," I typed: With ActiveDocument .Bookmarks("Decedent").Range _ .InsertBefore TextBox1 .Bookmarks("Venue").Range _ .InsertBefore TextBox2 .Bookmarks("Estate Number").Range _ InsertBefore TextBox3 .Bookmarks("Personal Representative").Range _ .InsertBefore TextBox4 .Bookmarks(Date of Death").Range _ .InsertBefore TextBox5 End With Userform1.Hide Ok, then I used Alt+Q to go back to Word and I saved the template and then I created a macro in that template called AutoNew which essentially said UserForm1.Show. So then I saved it and closed it and went to File, New, From my Computer and selected it and the dialog box popped up and I filled in all the variables and clicked on the button and it just keeps telling me "Runtime error 5941. Teh requested member of the collection does not exist. I have to tell you - it's making me crazy! Any suggestions you might have would be extremely welcome at this point. Thanks again. "Carol" wrote: Thanks for all the input. This is not a protected form but, rather, a template that I am configuring so that when it is selected, a dialog box (user form) will pop up to fill in the variables needed for the document to be complete. I am going start over from scratch today and will report on my success/failure. Thanks again! "Jay Freedman" wrote: And to answer your question about Alt+F9: - It's a toggle; every time you press Alt+F9, it either displays the field codes if the field results are showing, or it displays the field results if the field codes are showing. Press it twice and you're back where you started. - Alt+F9 by itself does not update the fields. That function is performed by F9 (without the Alt) for any fields that are currently selected; or by printing or going into Print Preview (assuming the "Update fields" option is checked in the Tools Options Print dialog); or, as Suzanne said, by having "Calculate on exit" checked for a form field in a protected form when that form field is the source for the Ref field. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
#15
|
|||
|
|||
Wow! Thanks Jay! Now it's all starting to make a little more sense to me. I
Wow Jay! It's starting to make a little more sense to me now. Thank you so much! I will try what you said and let you know how it goes. I'm glad that you said it wasn't intuitive to you either. I guess that's what I'm looking for - some kind of book or tutorial that will make it more intuitive for me so that I can look at the document I want to code and will readily know...oh...I want to use that code. I suppose it all comes with time and practice eh? If you know of any user friendly books, please let me know. I just recently purchased "Writing Word Macros" and that is a help. I'll let you know tomorrow how this works out for me. Again, many thanks. "Jay Freedman" wrote: Hi Carol, There are a lot of interrelated things going on in your document and its code, and it's a hard to cover them all at one go. Still, let's try to cover them one at at time. 1. A bookmark is just a name for a location in the document. It doesn't have any active properties -- it can't make things happen. Fields like the Ref field can do things, and macros/userforms are all about doing things, but bookmarks just lie there. Think of bookmarks and text as nouns, and macros/userforms and some fields as verbs. So the userform code uses the bookmark as a location to stuff some text into the document. Other than the text appearing there, *nothing* happens. The Ref fields don't find out about the new text unless you somehow tell them to update themselves (here, "update" means "make a copy of the bookmark's contents and display that copy at the Ref field's location"). A few responses ago, I said that F9 updates fields, and so does printing or going to Print Preview. One other thing that can cause an update is to put this line of code in your userform's CommandButton1_Click() procedure, just before the Hide statement: ActiveDocument.Fields.Update [Everything in Word is complicated. In this case, the complication is that the line of code only updates fields in the body of the document, not in headers, footers, or textboxes. I'll assume for now that this doesn't make any difference in your document.] 2. Now we come to the difference between using the .InsertBefore method and using the approach in the article I recommended. This is completely unintuitive, even to me. As I said, a bookmark is just a named location in the text. It can cover one or more characters, or it can be collapsed to a single point between characters, and it behaves differently depending on which it is. If the bookmark is collapsed to a point (because you had nothing selected when you created it), then the .InsertBefore method will insert new text *after* the bookmark, *outside* it. (I think this behavior is a VBA bug -- the new text should go before the bookmark.) The bookmark will remain empty. If a Ref field points to that bookmark, then updating the field will cause it to display nothing -- because that's what's inside the bookmark, nothing. If the bookmark covers one or more characters (which could be spaces), then the .InsertBefore method inserts the new text inside the bookmark before the existing contents. This is the only case in which it does what you expect. Afterward, updating the Ref field that points to the bookmark will show a copy of the bookmark's contents, including both the new text and the old contents. This works ok as long as you only insert new text once. Try it again and you get *both* sets of text in the bookmark, and *both* sets reflected in the Ref field. The method shown in the InsertingTextAtBookmark.htm article -- assigning the new text to the range of the bookmark, and then re-inserting the bookmark to cover the inserted text -- gives you exactly what you need, predictably and with the ability to use the same bookmark again. 3. The expression "Dim BMRange As Range" tells VBA that you're going to use a variable named BMRange, and that it's going to represent a range -- that is, a particular piece of the document. (The "Dim" is short for "Dimension" and is a leftover from much older programming languages.) After that, the statement that begins with "Set BMRange =" finds the range that corresponds to the named bookmark, and assigns that range to the variable BMRange. That way you'll be able to use the variable to re-insert the bookmark later. The code you showed earlier needs to be rewritten like this. Notice that the variable BMRange can be re-used to point to different ranges at different times during the execution of the code. Private Sub CommandButton1_Click() Dim BMRange As Range With ActiveDocument Set BMRange = .Bookmarks("Decedent").Range BMRange.Text = TextBox1 .Bookmarks.Add "Decedent", BMRange Set BMRange = .Bookmarks("Venue").Range BMRange.Text = TextBox2 .Bookmarks.Add "Venue", BMRange Set BMRange = .Bookmarks("EstateNumber").Range BMRange.Text = TextBox3 .Bookmarks.Add "EstateNumber", BMRange Set BMRange = .Bookmarks("PersonalRepresentative").Range BMRange.Text = TextBox4 .Bookmarks.Add "PersonalRepresentative", BMRange Set BMRange = .Bookmarks("DateOfDeath").Range BMRange.Text = TextBox5 .Bookmarks.Add "DateOfDeath", BMRange End With ActiveDocument.Fields.Update UserForm1.Hide End Sub -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org On Wed, 30 Mar 2005 15:19:05 -0800, "Carol" wrote: Hi Jay, I stepped through the code and had just about decided that the problem was just what you said because the error popped up at the two separate words. So now I have fixed the bookmarks and the code so that they are the same and they do indeed fall in right where they should, but the ref fields are not working and as you have seen, I am very new to this aspect of word, and even after reading the article that you sent to me, I am still very unsure as to how I should write the code for the ref fields. I guess the problem is that I don't understand how using InsertBefore only screws up the ref fields and not the actual bookmarks. Also, reading the article is a bit difficult for me because I don't understand what Dim BMRange means. Are there any articles or tutorials that can help me with this? Or could you tell me how to do one so that I can go from there? I so appreciate your's and Suzanne's help! "Jay Freedman" wrote: Hi Carol, You're getting there... but you have to exactly match the names of the bookmarks in the code. Since spaces aren't legal in bookmark names, I can tell right away some of them are wrong. Look at the names in the list when you bring up the Insert Bookmark dialog, and make the names in the code *exactly* the same. There's another complication with the way you userform is putting the text in the document. When you use the .InsertBefore command, the text goes *before* the bookmark, not *in* the bookmark. So when you do get the userform to finish without errors, the Ref fields won't have anything to show because the bookmarks themselves will be empty. The proper code for this is shown he http://word.mvps.org/FAQs/MacrosVBA/...AtBookmark.htm -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Carol wrote: I started from scratch with the document. In the spots where I wanted the different variables, I clicked on Insert | Bookmark and then typed in the name and clicked on Add. Where a variable was used more than once I clicked on Insert | Fields and Ref and clicked ont he Bookmark that it pointed to. Then I went to the Visual Basic Editor and inserted the User Form and added labels and textboxes for all of the bookmarks. I then added a command button and named it ok. After that I right-clicked on the command button and chose View Code. Once there, in between "Private Sub CommandButton1_Click()" and "End Sub," I typed: With ActiveDocument .Bookmarks("Decedent").Range _ .InsertBefore TextBox1 .Bookmarks("Venue").Range _ .InsertBefore TextBox2 .Bookmarks("Estate Number").Range _ InsertBefore TextBox3 .Bookmarks("Personal Representative").Range _ .InsertBefore TextBox4 .Bookmarks(Date of Death").Range _ .InsertBefore TextBox5 End With Userform1.Hide Ok, then I used Alt+Q to go back to Word and I saved the template and then I created a macro in that template called AutoNew which essentially said UserForm1.Show. So then I saved it and closed it and went to File, New, From my Computer and selected it and the dialog box popped up and I filled in all the variables and clicked on the button and it just keeps telling me "Runtime error 5941. Teh requested member of the collection does not exist. I have to tell you - it's making me crazy! Any suggestions you might have would be extremely welcome at this point. Thanks again. "Carol" wrote: Thanks for all the input. This is not a protected form but, rather, a template that I am configuring so that when it is selected, a dialog box (user form) will pop up to fill in the variables needed for the document to be complete. I am going start over from scratch today and will report on my success/failure. Thanks again! "Jay Freedman" wrote: And to answer your question about Alt+F9: - It's a toggle; every time you press Alt+F9, it either displays the field codes if the field results are showing, or it displays the field results if the field codes are showing. Press it twice and you're back where you started. - Alt+F9 by itself does not update the fields. That function is performed by F9 (without the Alt) for any fields that are currently selected; or by printing or going into Print Preview (assuming the "Update fields" option is checked in the Tools Options Print dialog); or, as Suzanne said, by having "Calculate on exit" checked for a form field in a protected form when that form field is the source for the Ref field. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
#16
|
|||
|
|||
Hello Jay,
I redid my template this morning and received another error and so I scrapped it and started anew and lo and behold, it's working perfectly. So now that I have managed to make this thing work at last I am emboldened to try yet a different step. I now want to add a clear and a cancel button to my user form. So this is my seminal stab at coding it: Private Sub cmdClear_Click() BMRange.Text = TextBox1 = True TextDecedent.Value = Null How far off am I? And I'd still like to know if you could steer me toward a good user-friendly book. Thanks ever so much for your help! "Carol" wrote: Wow! Thanks Jay! Now it's all starting to make a little more sense to me. I Wow Jay! It's starting to make a little more sense to me now. Thank you so much! I will try what you said and let you know how it goes. I'm glad that you said it wasn't intuitive to you either. I guess that's what I'm looking for - some kind of book or tutorial that will make it more intuitive for me so that I can look at the document I want to code and will readily know...oh...I want to use that code. I suppose it all comes with time and practice eh? If you know of any user friendly books, please let me know. I just recently purchased "Writing Word Macros" and that is a help. I'll let you know tomorrow how this works out for me. Again, many thanks. "Jay Freedman" wrote: Hi Carol, There are a lot of interrelated things going on in your document and its code, and it's a hard to cover them all at one go. Still, let's try to cover them one at at time. 1. A bookmark is just a name for a location in the document. It doesn't have any active properties -- it can't make things happen. Fields like the Ref field can do things, and macros/userforms are all about doing things, but bookmarks just lie there. Think of bookmarks and text as nouns, and macros/userforms and some fields as verbs. So the userform code uses the bookmark as a location to stuff some text into the document. Other than the text appearing there, *nothing* happens. The Ref fields don't find out about the new text unless you somehow tell them to update themselves (here, "update" means "make a copy of the bookmark's contents and display that copy at the Ref field's location"). A few responses ago, I said that F9 updates fields, and so does printing or going to Print Preview. One other thing that can cause an update is to put this line of code in your userform's CommandButton1_Click() procedure, just before the Hide statement: ActiveDocument.Fields.Update [Everything in Word is complicated. In this case, the complication is that the line of code only updates fields in the body of the document, not in headers, footers, or textboxes. I'll assume for now that this doesn't make any difference in your document.] 2. Now we come to the difference between using the .InsertBefore method and using the approach in the article I recommended. This is completely unintuitive, even to me. As I said, a bookmark is just a named location in the text. It can cover one or more characters, or it can be collapsed to a single point between characters, and it behaves differently depending on which it is. If the bookmark is collapsed to a point (because you had nothing selected when you created it), then the .InsertBefore method will insert new text *after* the bookmark, *outside* it. (I think this behavior is a VBA bug -- the new text should go before the bookmark.) The bookmark will remain empty. If a Ref field points to that bookmark, then updating the field will cause it to display nothing -- because that's what's inside the bookmark, nothing. If the bookmark covers one or more characters (which could be spaces), then the .InsertBefore method inserts the new text inside the bookmark before the existing contents. This is the only case in which it does what you expect. Afterward, updating the Ref field that points to the bookmark will show a copy of the bookmark's contents, including both the new text and the old contents. This works ok as long as you only insert new text once. Try it again and you get *both* sets of text in the bookmark, and *both* sets reflected in the Ref field. The method shown in the InsertingTextAtBookmark.htm article -- assigning the new text to the range of the bookmark, and then re-inserting the bookmark to cover the inserted text -- gives you exactly what you need, predictably and with the ability to use the same bookmark again. 3. The expression "Dim BMRange As Range" tells VBA that you're going to use a variable named BMRange, and that it's going to represent a range -- that is, a particular piece of the document. (The "Dim" is short for "Dimension" and is a leftover from much older programming languages.) After that, the statement that begins with "Set BMRange =" finds the range that corresponds to the named bookmark, and assigns that range to the variable BMRange. That way you'll be able to use the variable to re-insert the bookmark later. The code you showed earlier needs to be rewritten like this. Notice that the variable BMRange can be re-used to point to different ranges at different times during the execution of the code. Private Sub CommandButton1_Click() Dim BMRange As Range With ActiveDocument Set BMRange = .Bookmarks("Decedent").Range BMRange.Text = TextBox1 .Bookmarks.Add "Decedent", BMRange Set BMRange = .Bookmarks("Venue").Range BMRange.Text = TextBox2 .Bookmarks.Add "Venue", BMRange Set BMRange = .Bookmarks("EstateNumber").Range BMRange.Text = TextBox3 .Bookmarks.Add "EstateNumber", BMRange Set BMRange = .Bookmarks("PersonalRepresentative").Range BMRange.Text = TextBox4 .Bookmarks.Add "PersonalRepresentative", BMRange Set BMRange = .Bookmarks("DateOfDeath").Range BMRange.Text = TextBox5 .Bookmarks.Add "DateOfDeath", BMRange End With ActiveDocument.Fields.Update UserForm1.Hide End Sub -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org On Wed, 30 Mar 2005 15:19:05 -0800, "Carol" wrote: Hi Jay, I stepped through the code and had just about decided that the problem was just what you said because the error popped up at the two separate words. So now I have fixed the bookmarks and the code so that they are the same and they do indeed fall in right where they should, but the ref fields are not working and as you have seen, I am very new to this aspect of word, and even after reading the article that you sent to me, I am still very unsure as to how I should write the code for the ref fields. I guess the problem is that I don't understand how using InsertBefore only screws up the ref fields and not the actual bookmarks. Also, reading the article is a bit difficult for me because I don't understand what Dim BMRange means. Are there any articles or tutorials that can help me with this? Or could you tell me how to do one so that I can go from there? I so appreciate your's and Suzanne's help! "Jay Freedman" wrote: Hi Carol, You're getting there... but you have to exactly match the names of the bookmarks in the code. Since spaces aren't legal in bookmark names, I can tell right away some of them are wrong. Look at the names in the list when you bring up the Insert Bookmark dialog, and make the names in the code *exactly* the same. There's another complication with the way you userform is putting the text in the document. When you use the .InsertBefore command, the text goes *before* the bookmark, not *in* the bookmark. So when you do get the userform to finish without errors, the Ref fields won't have anything to show because the bookmarks themselves will be empty. The proper code for this is shown he http://word.mvps.org/FAQs/MacrosVBA/...AtBookmark.htm -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Carol wrote: I started from scratch with the document. In the spots where I wanted the different variables, I clicked on Insert | Bookmark and then typed in the name and clicked on Add. Where a variable was used more than once I clicked on Insert | Fields and Ref and clicked ont he Bookmark that it pointed to. Then I went to the Visual Basic Editor and inserted the User Form and added labels and textboxes for all of the bookmarks. I then added a command button and named it ok. After that I right-clicked on the command button and chose View Code. Once there, in between "Private Sub CommandButton1_Click()" and "End Sub," I typed: With ActiveDocument .Bookmarks("Decedent").Range _ .InsertBefore TextBox1 .Bookmarks("Venue").Range _ .InsertBefore TextBox2 .Bookmarks("Estate Number").Range _ InsertBefore TextBox3 .Bookmarks("Personal Representative").Range _ .InsertBefore TextBox4 .Bookmarks(Date of Death").Range _ .InsertBefore TextBox5 End With Userform1.Hide Ok, then I used Alt+Q to go back to Word and I saved the template and then I created a macro in that template called AutoNew which essentially said UserForm1.Show. So then I saved it and closed it and went to File, New, From my Computer and selected it and the dialog box popped up and I filled in all the variables and clicked on the button and it just keeps telling me "Runtime error 5941. Teh requested member of the collection does not exist. I have to tell you - it's making me crazy! Any suggestions you might have would be extremely welcome at this point. Thanks again. "Carol" wrote: Thanks for all the input. This is not a protected form but, rather, a template that I am configuring so that when it is selected, a dialog box (user form) will pop up to fill in the variables needed for the document to be complete. I am going start over from scratch today and will report on my success/failure. Thanks again! "Jay Freedman" wrote: And to answer your question about Alt+F9: - It's a toggle; every time you press Alt+F9, it either displays the field codes if the field results are showing, or it displays the field results if the field codes are showing. Press it twice and you're back where you started. - Alt+F9 by itself does not update the fields. That function is performed by F9 (without the Alt) for any fields that are currently selected; or by printing or going into Print Preview (assuming the "Update fields" option is checked in the Tools Options Print dialog); or, as Suzanne said, by having "Calculate on exit" checked for a form field in a protected form when that form field is the source for the Ref field. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
#17
|
|||
|
|||
Hi Carol,
How far off are you? Wellll... pretty far, unfortunately. First establish what you want to happen when the user clicks the Clear button. Should all the textboxes on the userform and all the contents of the bookmarks in the document be set to nothing? (It doesn't make sense to me to clear only one pair.) Or would it be sufficient to clear only the userform's boxes, and assume that the user will eventually fill them and click OK, and the document's bookmarks get refilled then? I'll assume the first choice for now. One fact you need is that in VBA there is something known as an empty string, and it's represented by a pair of double quotes with nothing between them: "" [This is not the same thing as Null, which the help defines as "A value indicating that a variable contains no valid data."] You clear a textbox by setting its text to an empty string, and the same for a bookmark but then you need to re-insert the bookmark. Except for clearing the textboxes, the code for the Clear button would be a lot like that for the OK button, like this (I've only shown the first two textbox/bookmark pairs, and you need to add all the others): Private Sub cmdClear_Click() Dim BMRange As Range With ActiveDocument TextBox1.Text = "" Set BMRange = .Bookmarks("Decedent").Range BMRange.Text = "" .Bookmarks.Add "Decedent", BMRange TextBox2.Text = "" Set BMRange = .Bookmarks("Venue").Range BMRange.Text = "" .Bookmarks.Add "Venue", BMRange ' more here.... End With ActiveDocument.Fields.Update End Sub Notice that, unlike the CommandButton1_Click() we discussed before, you don't put a Userform1.Hide statement in this procedure because you want the userform to stay on screen to be filled out. I don't really have much advice about VBA books. You said you bought "Writing Word Macros", and that's better than most, but the field is pretty limited. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Carol wrote: Hello Jay, I redid my template this morning and received another error and so I scrapped it and started anew and lo and behold, it's working perfectly. So now that I have managed to make this thing work at last I am emboldened to try yet a different step. I now want to add a clear and a cancel button to my user form. So this is my seminal stab at coding it: Private Sub cmdClear_Click() BMRange.Text = TextBox1 = True TextDecedent.Value = Null How far off am I? And I'd still like to know if you could steer me toward a good user-friendly book. Thanks ever so much for your help! |
#19
|
|||
|
|||
On Thu, 31 Mar 2005 17:59:06 -0800, "Carol"
wrote: Thanks Jay. I do appreciate the time that you have taken to help me with this endeavor. I have seen that the field is pretty limited insofar as books go, but there must be a way to learn this without pestering the folks who already know it. Where would I find the VBA language and it's meanings? There must be some documentation somewhere. It all makes sense after you explain it to me. I suppose it's like anything else then; trial and error and the more you practice, the better you get? Please feel free to send me any helpful information The documentation for the VBA language is all in the Help topics. Type any keyword in the VBA editor, put the cursor on it and press F1 to get the help topic about that keyword. There are also some overview articles, but they're a bit harder to find. If you're away from your Word installation, you can find the complete VBA reference for Word 2003 at http://msdn.microsoft.com/library/en...HV01132015.asp (for the parts common to all Office programs) and http://msdn.microsoft.com/library/en...HV01135786.asp (for the parts specific to Word). With some pride, allow me to point to the MVP site, particularly http://word.mvps.org/FAQs/MacrosVBA.htm and the pages linked from it. Finally, don't hesitate to ask questions here. That's what we're here for. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
#20
|
|||
|
|||
Thank you again for all of your help. I always visit the MVP pages for help.
I'm aspiring to be an MVP someday! I'm sure I'll be posting more questions as I go along. Thanks! You've been grand. Carol "Jay Freedman" wrote: On Thu, 31 Mar 2005 17:59:06 -0800, "Carol" wrote: Thanks Jay. I do appreciate the time that you have taken to help me with this endeavor. I have seen that the field is pretty limited insofar as books go, but there must be a way to learn this without pestering the folks who already know it. Where would I find the VBA language and it's meanings? There must be some documentation somewhere. It all makes sense after you explain it to me. I suppose it's like anything else then; trial and error and the more you practice, the better you get? Please feel free to send me any helpful information The documentation for the VBA language is all in the Help topics. Type any keyword in the VBA editor, put the cursor on it and press F1 to get the help topic about that keyword. There are also some overview articles, but they're a bit harder to find. If you're away from your Word installation, you can find the complete VBA reference for Word 2003 at http://msdn.microsoft.com/library/en...HV01132015.asp (for the parts common to all Office programs) and http://msdn.microsoft.com/library/en...HV01135786.asp (for the parts specific to Word). With some pride, allow me to point to the MVP site, particularly http://word.mvps.org/FAQs/MacrosVBA.htm and the pages linked from it. Finally, don't hesitate to ask questions here. That's what we're here for. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
#21
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
MULTIPLE INSTANCES OF THE SAME BOOKMARK IN A USER FORM
I just wanted to post a big "thank you" for this previous post...I was having
problems with my user form as well (spaces kept getting inserted after all the cross-references) and Jay's code below fixed it. I had seen this code on the MS website somewhere but wasn't exactly sure what to do with it...these instructions were very helpful and now it works like a charm. Thanks! |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Multiple User File Editing | Microsoft Word Help | |||
Find AND Display Multiple Instances | Microsoft Word Help | |||
why word 2000 mail merge opens multiple instances of access table. | Mailmerge | |||
Multiple Instances of Word 2k2 | New Users | |||
Multiple user accounts and trial version of Word | Microsoft Word Help |