Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bookmark Names 1

Status
Not open for further replies.

keenanbr

Programmer
Oct 3, 2001
469
IE
I am looping through bookmarks but It seems to get confused when I have similar bookmark names. How many chars are significent in bookmarks names

Regards,

 
How many chars are significent in bookmarks names"

All of them. All the chars in ANY name of an object are significant.

Perhaps post your code that you are using to loop. Are you doing it by name - as it seems - or as bookmarks, i.e
Code:
For Each Bookmark In ...

Also: "It seems to get confused" is very very vague. It tells us nothing. Please be precise and clear.

faq219-2884

Gerry
My paintings and sculpture
 
Hi keenanbr,

This sounds rather like you're persisting with the approach you outlined in
As I said then, you don't need a macro for this (even if you have 300 forms) - it can all be done with REF fields and a simple 'calculate on exit' setting on a formfield that has the bookmark name that you want to cross-reference.

Cheers

[MS MVP - Word]
 
Thanks Macropod but this is something different.
 
Just figured out what's going on. When I list all the bookmarks through VBA code, one bookmark shows up twice at the expense of another. I changed the names of the two bookmarks in question. All works fine now. The first 6 characters of the bookmarks names were the same. This is what I originally suspected (i.e. that all the chars were no significent). Is this correct or is there another reason?
 
Sorry, but you are incorrect. ALL the chars are significant.

"When I list all the bookmarks through VBA code, one bookmark shows up twice at the expense of another. "

I have no idea what you mean by "at the expense of another", but I flatly do not believe you have a bookmark that "shows up twice". You can NOT have two bookmarks with the same name.

Yes, you could have two bookmarks with the first 6 characters the same...but so what? The rest of them HAVE to be different.

Further, it is possible that you are getting mixed up between bookmarks and formfields.

Say you have a formfield. Its name is Text1. Check in Properties and the bookmark name is Text1. This also shows up under Bookmarks as.....Text1.

Now go and select some text. Anywhere. It does not matter, just select something. Insert > Bookmarks and name it Text1.

Under Bookmarks, there is still a Text1 bookmark...but it is no longer the formfield. It is the text you just selected. If you check the Properties of the formfield, it no longer has any bookmark name!. The bookmark name of the formfield is blank...because it no longer HAS a bookmark.

All formfields CAN have bookmarks. However, a formfield is not a bookmark. It is a mistake to think of them as equivalent. If you copy and paste a formfield, the pasted formfield has NO name, and NO bookmark.

If you are actually doing things to formfields, generally (but not always) it is better to use formfield objects and their properties. Not bookmarks.

On the other hand, if you are using REF fields - as macropod mentions in the linked thread - then indeed you are using the bookmark OF a formfield for reference.

faq219-2884

Gerry
My paintings and sculpture
 
I appreciate what you are saying and I cant understand what's happening. I have no form fields just bookmarks and text. If I run this piece of code


If ActiveDocument.Bookmarks.Count > 0 Then
For Each bkMark In ActiveDocument.Bookmarks
bkName = bkMark.Name

If ActiveDocument.Bookmarks.Exists(bkName) Then
debug.print bkName
End If
Next bkMark
End If


One bookmark shows up twice and one is left out
 
Hi keenanbr,

Your code is working too hard! Since you're looping through the bookmarks collection, there's no need to test for the existence of the bookmark name after you've retrieved it from the collection. All you need is:
Code:
If ActiveDocument.Bookmarks.Count > 0 Then
       For Each bkMark In ActiveDocument.Bookmarks
            debug.print bkMark.Name
       Next bkMark
End If
or maybe:
Code:
If ActiveDocument.Bookmarks.Count > 0 Then
       For Each bkMark In ActiveDocument.Bookmarks
            bkName = bkMark.Name
            debug.print bkName
       Next bkMark
End If
Even so, I can't see anything in your code that would cause the problems you say you're having.

Cheers




[MS MVP - Word]
 
just a thought, are you using something like this to dim bkName?

Code:
Dim bkName As String * n

that would explain why they are the same.


mr s. <;)

 
Thanks to all who replied.

I just have Dim bkName as string

It seems very strange but if I make thhem unique for the first 6 chars I have no problems. But this can't be right because I have other bookmarks which are not unique for the first 6 chars. So I can get aaround the problem but I don't understand why it is happening.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top