Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

word automation - move cursor to bookmark 1

Status
Not open for further replies.

white605

Technical User
Jan 20, 2003
394
US
I have inserted a bookmark into a word doc named TXT with the command- loselection.bookmarks.add("body")

I have searched and tried many combinations of code trying to move to the bookmark when i later open the document.
1. loselection.goto.bookmarks(0,"TXT",0)
2. loselection.goto.bookmarks("TXT")
3. loselection.goto.bookmarks(wdgotobookmark,;
"TXT",wdsortbyname,.f.)
And several more combinations with no luck
A tip go get me started will be greatly appreciated!
wjwjr
 
Don't go to the bookmark. Just act on it:

loDoc.Bookmarks("Txt").Range.Text = "My new data"

In general, the best way to do automation with Word is with range objects rather than the selection object.

Tamar
 
Tamar,
That works well, and i will read up on the range objects. In this certian instance i am building a document, programatically naming and saving it,conditionally inserting several lines, and then presenting it to the user to continue and need to position the cursor in the right place for them to type several (5 or 6 paragraphs, using the editing abilities of word...I was using a bookmark at a way to find the starting position. There might be a better way to get there, im not sure?
thanks
wjwjr
 
Mike,
thanks for the tip. I find the following when testing:

In a document with 6 lines of text and a bookmark at the bottom, i keep getting invalid paramaters with

oWord.Selection.GoTo(-1, 1, "MyBookmark")

*move down to the bottom
FOR i=1 TO 6
loword.selection.movedown
endfor

loWord.Selection.GoTo(1,1) - takes you back to the top

I will keep looking and post back what i find.
wjwjr
 

White,

I'm not really an expert on this. I got that code by recording a macro in Word trying to translate its code from VBA to VFP. But I wasn't sure about all the parameters.

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
The Help for Goto is misleading. If I remember correctly, you need to omit the second and third parameters when you're addressing bookmarks.

Tamar
 
thanks, i will give that a try
wjwjr
 
Tamar,Mike
Thanks for the nudge in the right direction. I found that

*move insertion point to the first character in line 4
#define wdgotoline 3
#define wdgotoabsolute 1
oword.selection.goto(wdgotoline,wdgotoabsolute,4)

and

*move insertion point to bookmark named "three" odoc.Bookmarks("three").Select

I was unable to get this to work with any set of parameters
#define wdgotobookmark -1
oword.selection.goto(wdgotobookmark,"three")

wjwjr
 
The GoTo method has 4 parameters. If I remember right, you need to pass all 4 for bookmarks, with the middle two omitted:

oWord.Selection.Goto(wdgotobookmark, , , "three")

Actually, I just looked it up where I had it and this should work.

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top