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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Really easy questions about bookmarks

Status
Not open for further replies.

kirilisa

Programmer
Aug 9, 2005
3
AU
Hello, I am running into a probably abominably easy to fix VBA problem. I have NO idea how to code in VBA but I have been given a task to fix this piece of code that is broken and the VBA books I have will not tell me what I want to know nor can I find it online! So my apologies. Anyway.

Basically I have this enormous macro which is supposed to turn a Word doc into HTML. I'm running into problems when turning bookmarks into HTML anchors in a bunch of references/footnotes in the doc. the superscript in the text is linked down to wahtever its footnote is and at the end of the footnote there is a 'return to text' which links back to the superscript in question.

Problem is, when I select the superscript using Selection.Find and then replace that text as follows

Selection.Text = "<a href=" & dblQuote & hrefTemp & dblQuote & ">" & tempTextToDisplay & "</a>"

the bookmark that was associated with the superscript gets overwritten, so when I get down to the related 'Return to Text' to make the return anchor, the bookmark it refers to is gone and the whole thing craps out.

So things I would like to know:
1) How can I make it so that when I select, e.g. superscript 14 via Selection.Find it doesn't also select the surrounding bookmark?

2)How do I know what is the name of the bookmark that is associated with a selection (i.e. if I have selected superscript 14, how do I know that the bookmark surrounding it is named ref14)?

3) Likewise, how do I know what is the value of a the hyperlink that is associated with a selection? That is, if I have 'Return to text' selected, how do I know that it is hyperlinked to a bookmark name 'ref14'?

I am terribly frustrated.

Thanks!
 
Aaarrrgggh. I hate this crap. This issue has come again and again. Using Word to change existing documents into HTML is a pain, a pain, a pain. My sympathies.

I will try to help.

#3 - If the hyperlink within a Selection is to a bookmark with the document:
Code:
Selection.Hyperlinks(1).Name
will return the name of bookmark. .Address will return blank.

If the hyperlink within a Selection is to an external object:
Code:
Selection.Hyperlinks(1).Address
will return the address of the target. .Name will return the same.

.Name and .Address return the same value.

#2
Code:
Selection.Bookmarks(1).Name

1) How can I make it so that when I select, e.g. superscript 14 via Selection.Find it doesn't also select the surrounding bookmark?

Hmmmm. If the "surrounding" bookmarks is also superscript 14...then of course if that is what you are searching for, then that is what you will get.

You seem to to be using Selection.Find to do your stuff. This may not be the best route. I don't know what precisely what you are doing, but maybe it would be better to use footnote objects, rather than Selection.Find.

Hope this helps.

Gerry
My paintings and sculpture
 
Hi Gerry,

Thanks a lot for your answer, it does clarify things somewhat.

Do you know, though, if I can find out what bookmark is associated with a selection? That is, not what bookmark a selection is hyperlinked/pointed to, but what bookmark is actually *at/within* that selection that other links elsewhere in the document can point to.

For instance, if I have a reference number/superscript 14, which has the bookmark name 'ref14' and when you click on it, directs you to endnote 14, how, when I have the actual reference number selected, is there anyway I can get the information "what you have selected is associated with bookmark 'ref14'"?

Thanks!
 
Do you know, though, if I can find out what bookmark is associated with a selection? That is, not what bookmark a selection is hyperlinked/pointed to, but what bookmark is actually *at/within* that selection that other links elsewhere in the document can point to.
Please try and read posts carefully. I stated this. This is a repeat of your question #2. Here it is again.

If the Selection is in a bookmark, then
Code:
Selection.Bookmark(1).Name
returns that bookmark name. Assuming there is only ONE bookmark in the Selection. You can of course nest bookmarks.

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top