Word 2010 automation: 'goto bookmark'

I have a program written in Delphi-7 which opens a new Word document which is based on a template.
Once the document is open, the automation jumps to a bookmark (predefined in the template) and adds some text there.
The following code works fine in Word 2003 but causes a invalid variant operation error message in Word 2010 (I have omitted try/except blocks for the sake of clarity).

wrdapp:= CreateOleObject ('Word.Application');
wrdDoc:= wrdapp.documents.add (wrdApp.Options.DefaultFilePath[wdUserTemplatesPath] + '1.dot'
wrdApp.selection.goto (wdGotoBookmark, unassigned, unassigned, 'B1')

If I replace the third line with

wrdDoc.bookmarks.item ('B1').select

the program works fine in Word 2003 but still crashes in Word 2010.

What is the correct code for Word 2010 to 'go to' the bookmark?

6
задан Drew Gaynor 2 February 2012 в 18:43
поделиться