Bookmarks

C

Clayton L. Wilson

I have a file in which I used a macro to convert the first
few characters on each line into bookmarks. This works
great.
My question: How do I write another macro to "reverse"
what I have done? I load the file in, run the macro and
restore the bookmarks back to there text form in their
original location. Any help would be greatly appreciated,
thanks.
 
D

Doug Robbins - Word MVP

Hi Clayton,

Use

Dim abm As Bookmark
For Each abm In ActiveDocument.Bookmarks
abm.Range = abm.Name
abm.Delete
Next abm

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
C

Clayton L. Wilson

This is not really what I was looking for. I don't want to delete the
bookmarks, I want to insert them into the document. for example:

"This is a line of text" The bookmark for the line is "hello"

After I run my macro, the line would read like this:

"helloThis is a line of text"
 
M

Mark Tangard

Clayton,

This will do what you describe:

Dim bmk As Bookmark
For Each bmk In ActiveDocument.Bookmarks
bmk.Range.InsertBefore bmk.Name
Next bmk

But -- not trying to second guess your intentions -- don't you
want something a little different from this? Isn't there any
separator needed between the bookmark name and its text?
 
C

Clayton L. Wilson

Yes, I do need to have separators around the bookmark
text. When I generate the bookmarks, the text look
something like this:
<A>mybookmark</A>this is a line of text.
I strip the <A> tags off. When I put the text back, I need
 
M

Mark Tangard

OK, then substitute this for the line inside the loop:

bmk.Range.InsertBefore "<A>" & bmk.Name & "</A>"
 

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