Copying Text to Bookmark Names

J

Jerry

In Word 2000, I have a document that lists a series of ID numbers, titles,
and other information, each in a five-paragraph set. Each paragraph within
each set has a unique paragraph style. I would like to develop a macro that
does the following for each set:

1. Use the text of the ID paragraph (style: "Web ID") as a bookmark name for
the title paragraph (style "Title").
2. Remove the ID paragraph.
3. Repeat for the entire document.

Thanks!
Jerry
 
J

Jean-Guy Marcil

Jerry said:
In Word 2000, I have a document that lists a series of ID numbers, titles,
and other information, each in a five-paragraph set. Each paragraph within
each set has a unique paragraph style. I would like to develop a macro that
does the following for each set:

1. Use the text of the ID paragraph (style: "Web ID") as a bookmark name for
the title paragraph (style "Title").
2. Remove the ID paragraph.
3. Repeat for the entire document.

Play with this to get you started:

Dim i As Long

With ActiveDocument
For i = Paragraphs.Count To 1 Step -1
If .Paragraphs(i).Style = "Web ID" Then
.Bookmarks.Add "ID_" & Left(.Paragraphs(i).Range.Text, _
Len(.Paragraphs(i).Range.Text) - 1), .Paragraphs(i + 1).Range
.Paragraphs(i).Range.Delete
End If
Next
End With


A few words regarding bookmarks:
The first character cannot be a number (This is why I include the "ID_"
string).
The length limit is 40 characters.
There cannot be any spaces in the bookmark names.
Names must be unique, if they are not, the new one will be created, but the
old one with the same name will be automatically removed.

So, depending on the nature of the content of your ID string of text, you
may need to tweak the code...
 
J

Jerry

Perfect; thanks!

Jean-Guy Marcil said:
Play with this to get you started:

Dim i As Long

With ActiveDocument
For i = Paragraphs.Count To 1 Step -1
If .Paragraphs(i).Style = "Web ID" Then
.Bookmarks.Add "ID_" & Left(.Paragraphs(i).Range.Text, _
Len(.Paragraphs(i).Range.Text) - 1), .Paragraphs(i + 1).Range
.Paragraphs(i).Range.Delete
End If
Next
End With


A few words regarding bookmarks:
The first character cannot be a number (This is why I include the "ID_"
string).
The length limit is 40 characters.
There cannot be any spaces in the bookmark names.
Names must be unique, if they are not, the new one will be created, but the
old one with the same name will be automatically removed.

So, depending on the nature of the content of your ID string of text, you
may need to tweak the code...
 

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