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

RE: Copying Text to Bookmark Names by JeanGuyMarcil

JeanGuyMarcil
Fri May 16 05:46:01 PDT 2008

"Jerry" wrote:

> 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...


RE: Copying Text to Bookmark Names by Jerry

Jerry
Sat May 17 10:52:00 PDT 2008

Perfect; thanks!

"Jean-Guy Marcil" wrote:

> "Jerry" wrote:
>
> > 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...
>