Use same bookmark more then once

P

paul

Dear All,

Is it possible to use for example bookmark Monthname more then once in a
document? I tried but it wont allow me to do so.
What I want to achieve is the following:

I have a document where, for example, the month of May is used several
times in various paragraphs. I dont want to find and replace May by June but
I want to create a form where you can select a month and then automaticly
replaced the new month name. I was thinking of creating bookmarks named
Monthname but it wont allow me to use this more then once.

Any ideas???

Best regards,

Paul from the Netherland.
 
D

Dave Lett

Hi Paul,

Good news, you can do what you want. Bad news, you can't do it the way
you've mentioned.

No, each bookmark must have a unique name. After you insert a bookmark, you
can insert a REF field that points to that bookmark, which will reproduce
the contents of your bookmark.

HTH,
Dave
 
P

paul

Dave,

You lost me completely, do I have to add n bookmarks if I use n time the
month of April??


Paul
 
D

Dave Lett

Hi Paul,

No, you add one bookmark ("MonthName").
Then, you add n number of Ref fields. They will look something like the
following when you have reveal field codes on.
Try this as a proof/demonstration of the concept.

Open a new document and type the word "April". Bookmark it and name the
bookmark MonthName.
Type REF MonthName. Highlight REF MonthName
Press CTRL + F9 (to convert the text to a field)
Press F9 (to update the field).
Copy the field and paste it any number of times you want.

HTH,
Dave
 
P

paul

Dave,

Never knew that I would use the Field section :) it works!!!! Thanks.
Now it will embark on VB forms to give it nice appearance.

thx again.

Paul.
 
P

paul

Hi Dave,

I created a form in VBA with the following code. The document hold a
bookmark Monthname and made several REF MonthName + CTRL F9 but it seems
when I click the CommandButton1 the value from TextBox1 is only shown on the
inserted bookmark and not duplicated to the field where I made the REF.

Do you have any ideas.

rgrds,

Paul.

Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
With ActiveDocument
.Bookmarks("MonthName").Range.Text = TextBox1.Value
End With
Application.ScreenUpdating = True
Unload Me
 
D

Doug Robbins - Word MVP

Get rid of the ScreenUpDating commands and use

With ActiveDocument
.Bookmarks("MonthName").Range.Text = TextBox1.Value
.Range.Fields.Update
End With

The fields need to be updated to get them to display the information that
they are referencing.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
P

paul

Doug,

I have used the code as mentioned but the {REF Monthname} field is not
updated, the only bookmark which is updated is the bookmark added by the
menu, the "primary" bookmark

Paul.
 
D

Doug Robbins - Word MVP

Are you sure that { REF Monthname } is a proper field, that is that the
field delimiters { } were inserted using Ctrl+F9.

Where are these fields located? If they are not in the main body of the
document, it will be necessary to access the story ranges where they appear
(or use ActiveDocument.PrintPreview then ActiveDocument.ClosePrintPreview)
to get them to update.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
P

paul

Hi Doug,

I have tripple checked the naming of the bookmark, the REF Monthname appears
in grey, when I select change field it dissapears. This is normal for a ref
name?
The fields are located in a blanc document.
I used the preview code without any success.

Paul.
 
D

Dave Lett

Hi Paul,

Great. You might have REF Monthname set up appropriately. However, if you
have a field that refers to a bookmark AND that bookmark is empty, then your
REF Monthname field will be empty, too. When you update a REF field that
points to a bookmark in your document that is empty, then the results of
that field are also empty.

HTH,
Dave
 
D

Doug Robbins - Word MVP

The month that your form is inserting into the document is NOT inside the
bookmark. As a result, the bookmark is empty so there is nothing for the
REF field to display.

If when you insert the bookmark into the template from which the document is
being created, you have a space selected so that with the display of
bookmarks turned on under Tools>Options>View, it looks like [] rather than |
as it does in your document and you use the following code in the user form

With ActiveDocument
.Bookmarks("MonthName").Range.InsertBefore = TextBox1.Value
.Range.Fields.Update
End With

the data from TextBox1 will be inserted inside the [] so that it looks like
[April]. Then your cross reference field will work.

You might also consider using { DOCVARIABLE MonthName } fields of which you
can have as many with the same variable as you want and then use the
following code to set the variable

With ActiveDocument
.Variables("MonthName").Value = TextBox1.Value
.Range.Fields.Update
End With
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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