bookmark

R

Rahul Aggarwal

I'm using Visual Studio 6 to write a Visual Basic app that opens an
existing word document template and makes a number of changes and
additions to it.

I'm having a difficult time in trying to, among other things, move the
cursor (the insertion point) to the end of the file or to a bookmark.
Here's the code:

Set CurrentDoc = GetObject("C:\data\SSATemplate.doc")
CurrentDoc.ActiveWindow.Visible = True

' Move cursor to a bookmark
CurrentDoc.ActiveWindow.Selection.Goto What:=wdGToBookmark,
Name:="PathDataStart"

/ Move cursor to the end of the document
CurrentDoc.ActiveWindow.Selection.Endkey Unit:=wdStory, Extend:=wdMove


The document opens with no problems but when I try to move the cursor
to the bookmark (the only bookmark in the entire document), I get the
error message:

Error 5102: You entered multiple destinations for a page, line,
footnote, endnote, or comment.

When I try to move the cursor to the end of the document, I get the
error message:

Error 4102: Bad parameter

I've tried everything I can think of to fix the problem, to no avail.

Any help would be appreciated.

Thanks in advance.
 
M

MSizlak

There are variety of ways to do both. Here is one for
each:

1. currentdoc.bookmarks("PathDataStart").Range.select

2. selection.start=currentdoc.range.end

Moe
 
R

Rahul Aggarwal

Thanks Moe,

But the document does not have a function called bookmarks. It has a
property "Bookmark".

Please tell me what to do.

Thanks
 
G

Guest

You're correct that a document object has no bookmarks
function. But I never said or implied it did.

A Word document has a bookmarks collection, which
contains individual bookmarks. Each bookmark can be
referred to by index number or name (the code I gave you
references it by the name you gave us). Each bookmark has
a range property, which has a select method.

Ergo, the code I gave you will work fine. Perhaps there
is some other error in your macro. Or perhaps I've been
sloppy and just don't see my error.

All the best,

Moe
 

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