Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2008

Tip: Looking for answers? Try searching our database.

Copying Text to Bookmark Names

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jerry - 15 May 2008 21:32 GMT
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
Jean-Guy Marcil - 16 May 2008 13:46 GMT
> 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
[quoted text clipped - 5 lines]
> 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...
Jerry - 17 May 2008 18:52 GMT
Perfect; thanks!

> > 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
[quoted text clipped - 30 lines]
> So, depending on the nature of the content of your ID string of text, you
> may need to tweak the code...
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.