How to use word automation to select content between two bookmarks in a document?

I am opening up a word document from a webpage using JavaScript. Please see my code below.

var WordApp = new ActiveXObject('Word.Application');
WordApp.Visible = true;
WordApp.Documents.Open('c:test.doc);

This launches Word 2003 and opens up test.doc which is located on my hard drive. I need to then select a chunk of text from within the word document.

After looking through the documentation on MSDN I can see there is a 'MoveStart' and 'MoveEnd' method that I can use.

Now, this works great if i supply a single character to start from and a single character to end at like the below example.

WordApp.Selection.MoveStartUntil('C');
WordApp.Selection.MoveEndUntil('t');

This code when the word doc opens up selects the content between the first capital C and lowercase t.

What i'd like to do is select between words. So I would want to say:

WordApp.Selection.MoveStartUntil('Dear…

So I can start my selection when the first instance of the word 'Dear' appears in the document.

Does anyone know how I can do this? Any help would be much appreciated.

Cheers
Tom

 Mail this post

Technorati Tags:

Like this post? Subscribe to my RSS feed and get loads more!