Bookmark question

L

LEU

Is there a way to open old documents and rename the bookmarks in it so that
the document can be used with a new template? An example is the person’s
name. In one old document the bookmark name is Text1 and in another its
MyName. In the new template its called Name.
 
S

Shauna Kelly

Hi LEU

As I understand it, you have one template, and a whole lot of documents. If
it's just a small number of documents, then you could open up each document
manually and insert bookmarks with the new names. But if it's a large number
of documents, then you'll need to write some code to do this.

In my view it would be easier to change one template than change all those
documents, and cope with peculiarities that may have crept in to the
documents over time.

Unless there are conflicts in the naming (as opposed to mere changes), then
you could use code in the template that copes with the different naming
conventions that have been used over time. As some ideas (in pseudo-code):

- if the "Text1" bookmark exists, insert the person's name here
- else, if the "MyName" bookmark exists, insert the person's name here
- else, if the "Name" bookmark exists... and so on

or

- if the "Text1" bookmark exists, then salutation = "Dear " & text1 bookmark
value
- else, if the "MyName" bookmark exists, then salutation = "Dear " &
"MyName" bookmark value
- and so on.

Post back with specific code if you need more help.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
L

LEU

Hi Shauna,

In my new template when I open my form to add/edit text in the document,
where Text1 is my textbox in the form, this is what I am trying to do:

oBMs As Bookmarks
If oBMs = ("Text55") Then
Text1.Value = oBMs("Text55").Range.Text
Else
Text1.Value = oBMs("Text20").Range.Text
End If


I get the error ' argument not optional'. What am I doing wrong?
 
S

Shauna Kelly

Hi

Is your form a separate dialog box, or is your form the word document
itself?

In any case..

This line
oBMs As Bookmarks
is not valid VBA code.

Perhaps you meant to say
dim oBMs as Bookmarks

If that's so, then oBMs is a variable that refers to the whole collection of
bookmarks in the document. And so this line
If oBMS = ("Text55") then
can't make sense, because the whole collection couldn't be ("Text55").

When you get an error, use F8 to step through the code line by line, and
work out what line of code is causing the error. Then fix that line and try
again.

There is some sample code that you might find useful at
http://www.word.mvps.org/FAQs/Userforms/CreateAUserForm.htm

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top