I'm new to VBA in word though have done a bit in excel. I have what I think will be a simple issue. In a document I want to autocomplete a number of fields from strings gathered from a userform and stored in variables. I can achieve this by using:
However I can only create a single bookmark called "name" in the document if I want to insert this same text in multiple places in the document how can I do this?ActiveDocument.Bookmarks("name").Range.Text = namestring
Last edited by tryer; 02-15-2012 at 03:29 PM.
Hi tryer,
I'd suggest using a custom document property instead of a bookmark, because bookmarks are all too easily deleted by accident. If you create a custom document property named 'MyProp' (with, say, a space as the default value), then you can update that property with your code and have DOCPROPERTY fields, coded as {DOCPROPERTY MyProp} wherever you need them in the document to replicate the value. The code to do this might look like:
Note: The field brace pairs (ie '{ }') for the DOCPROPERTY field example are created via Ctrl-F9 - you can't simply type them or copy & paste them from this message.With ActiveDocument .CustomDocumentProperties("MyProp").Text = namestring .Fields.Update End With
Cheers,
Paul Edstein
[MS MVP - Word]
Hi Paul,
Thanks for the help. unfortunately I can't get this to work, I have copied your suggeted code exactly and created the docpropert by using Ctrl+F9 then typing DOCPROPERTY myprop but when I run it I get the error:Invalid procedure call or argument
I'm sure the problem is that I just typed in the docproperty however when I use Insert>Docproperty I have a number of choices (starting with author) but custom is not among them
Hi tryer,
The property must be created before you can use it. To create the custom property, go to File|Properties|Advanced > Custom
Cheers,
Paul Edstein
[MS MVP - Word]
Ah thank you![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks