Pasting a Bookmark

J

JDM

In Word 2000, I have a document with a repeating pattern of paragraphs. In
order, the styles are:
1. Project ID (6 character identifier)
2. Project Title (5-20 word title)
3. Other paragraphs

If I were doing this manually, I would perform this procedure (over and over):
1. Select and cut the entire Project ID paragraph.
2. Select the entire Project Title paragraph.
3. Create a bookmark, pasting the Project ID into the "Bookmark Name" field.

So far, I haven't found a way to perform this last step through a macro. Help!

Jerry
 
D

Dave Lett

Hi Jerry,

Select the two paragraphs, and run the following routine:

Dim oRngID As Range
Dim oRngTitle As Range
Set oRngID = ActiveDocument.Range _
(Start:=Selection.Paragraphs(1).Range.Start, _
End:=Selection.Paragraphs(1).Range.End)
Set oRngTitle = ActiveDocument.Range _
(Start:=Selection.Paragraphs(2).Range.Start, _
End:=Selection.Paragraphs(2).Range.End)

ActiveDocument.Bookmarks.Add Name:=Left(oRngID.Text, Len(oRngID.Text) - 1),
Range:=oRngTitle
oRngID.Delete

If you don't have a valid bookmark name (Project ID), then the routine will
raise an error.

HTH,
Dave
 
G

Greg Maxey

Jerry,

I don't know exactly how you are performing steps 1 and 2 in your
existing code, but basically you need to assign the Project ID to a
string and the Project Title text as a range and then something like:

Sub Test()
Dim myString As String
Dim oRng As Word.Range
myString = "UniqueIDText"
'Set the project title text to a range value
Set oRng = Selection.Range
ActiveDocument.Bookmarks.Add myString, oRng
End Sub

Note - You will likely need to do some sort of validation on the
project ID as bookmark names can start with a number, or contain
spaces, special characters (except for underscore).
 

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