Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word Auto: trouble with .GoTo a Bookmark in Word
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01310785
Message ID:
01310877
Views:
10
Hi,

Thanks Yuri. I will give that a try. But maybe I am even thinking of this wrong - the intent was to move to a bookmark and then insert some text (or a table) after the bookmark. Should I instead just figure out the range for the bookmark and use the range's .InsertAfter() method to insert the text? Is one better than the other (or faster?).

Thanks,
Albert

>>Hi all,
>>
>>I am working away on a Word wrapper class for Word automation. I am having trouble with a wrapper function that tests and moves the insertion point to a bookmark (title GoToBookmark). It is failing on the actual Word command to .GoTo() in a range. I have tried changing the parameter order and have it in the order that the help file says but it fails saying "Bookmark not found". If I check loDocRange.Bookmarks.Count below, it returns 4 (the correct number). Any ideas?
>>
>>
>>
>>WITH THIS
>>
>>* (some set up code before this - including getting actve doc)
>>
>>* next, check that the bookmark exists in the bookmarks collection
>>
>>STORE loDocument.Bookmarks.Exists(tcBookmarkName) TO llBookmarkFound
>>
>>* [NOTE: this passes, the bookmark exists]
>>
>>* if bookmark not found, set errornum and return
>>IF NOT llBookmarkFound
>>   STORE -32 TO .inErrorNum
>>   RETURN .F.
>>ENDIF
>>
>>* otherwise, we should be able to go to it but wrap in error trap anyhow
>>
>>* set the range we want to "Go To" in
>>loDocRange = .ioActivedocument.Range()
>>
>>TRY
>>   * [NOTE: next line fails and goes to the "CATCH".  Outside of the
>>   * TRY/CATCH, it returns "Bookmark not found"
>>
>>   loDocRange.GoTo(wdGoToBookmark,wdGoToFirst,1,tcBookmarkName)
>>   STORE .T. TO llReturn
>>
>>CATCH
>>   STORE -33 TO .inErrorNum
>>   STORE .F. TO llReturn
>>ENDTRY
>>
>>ENDWITH && for WITH THIS
>>
>>RETURN llReturn
>>
>>
>
>Hi,
>
>The problem is that for tcBookmarkName the method RANGE.GoTO expects Bookmark ID, not Bookmark name.
>
>
>tcBookmarkID=oword.Activedocument.Range.Bookmarks(tcBookmarkName).Range.BookmarkID
>...Range.GoTo(wdGoToBookmark,wdGoToFirst,1,tcBookmarkID)
>
>
>You may use Selection object instead of Range; there bookmark names accepted:
>
>oWord.Selection.GoTo(wdGoToBookmark,,,tcBookmarkName)
>
>
>Good Luck
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform