MS Word 2003 Automation via JScript

R

Rick

Hi

I'm writing an XML driven mail merge type of application and cannot get
JScript to recognize the Selection object.

What I want to do is load a template document, populate the data, save the
document, insert a page break and then add the template again…round and round
again. Thus when ran it generates a number of reports all contained in the
same MS Word Doc file.

Alternatively is there a way to make Jscript automation any easier?

Thanks
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?Umljaw==?=,
I'm writing an XML driven mail merge type of application and cannot get
JScript to recognize the Selection object.
that's a bit vague... FWIW, the Selection object is a "child" of the Application
object. Do you specify app.Selection?

OTOH, it's best to avoid the Selection object as much as possible, and work with
the actual objects you wan to manipulate. For example, if your data targets are
bookmarks:
doc.Bookmarks("name").Range.Text = "my data"

or, just as an example how to work with a range

Word.Range rng;
rng = doc.Content;
rng.collapse 0;
rng.InsertBreak 7;
rng.End = doc.Content.End
rng.InsertFile "path to template"
What I want to do is load a template document, populate the data, save the
document, insert a page break and then add the template again…round and round
again. Thus when ran it generates a number of reports all contained in the
same MS Word Doc file.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply in
the newsgroup and not by e-mail :)
 
R

Rick

Thanks Cindy much appreciated.

My last question...is there anywhere where the constants for VBA are
defined? E.g. wdPageBreak=7. The only sources I've found so far are in
small scripts found by Google.

Thanks
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?Umljaw==?=,
My last question...is there anywhere where the constants for VBA are
defined? E.g. wdPageBreak=7.
If only all questions were this easy to answer <g>!

In Word's VBA Help files or through the Object Browser. Start Word,
Alt+F11. To open the object browser: F2. To go to any help topic, such
as for InsertBreak, type it in a module or in the Immediate window
(Ctrl+G), then press F1. You'll usually find the wd-Enums by clicking
the "überEnum" that's formatted in blue (as a link). Sometimes, you
need to use a combination of the two sources if the Help documentation
isn't thorough.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 

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