Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Control MS Word?

57 views
Skip to first unread message

Adrian Davis

unread,
Jun 17, 1999, 3:00:00 AM6/17/99
to
I'm new to the mysteries of programming under MS windows, so please forgive
my (probably) stupid question.

Is it possible using the "DDE" features of 8.1.1 and MS Word97 to:-

(*) Open/Close Word97?
(*) Open/Close specified documents?
(*) Create new documents?
(*) Print documents?
(*) Get data held in variables into a document?

If so, can anybody point me to some examples of how this is done?

Many Thanks,
=Adrian=


Bill Schongar

unread,
Jun 17, 1999, 3:00:00 AM6/17/99
to
Adrian Davis wrote:

>Is it possible using the "DDE" features of 8.1.1 and MS Word97 to:-


Yup, you sure can. You just have to figure out the mysteries of
Word's Macro language (WordBasic). You do have to do one
other thing first, though..

>(*) Open/Close Word97?

You can't open the initial DDE server (Word) through DDE. Subsequent
applications can be opened if your DDE server supports it, but
the app has to be launched somewhere. The easy way is going
to be using the "start" command (or "cmd /c start" on NT) to launch an
existing .DOC file. That way Word will start as long as the user has .DOC
files associated with Winword.

You can close Word through DDE, though, using the "FileExit"
WordBasic command.

>(*) Open/Close specified documents?


Yup. FileOpen, FileClose.

>(*) Create new documents?


Yup. FileNew.

>(*) Print documents?

Yup.. any guesses? ; ) Right, FilePrint!


>(*) Get data held in variables into a document?


Yup, depends on which way you're trying to go -
you can send TCL data into the document, or you can
retrieve data from specific locations (or Macro components)
into your TCL app.

>If so, can anybody point me to some examples of how
>this is done?

Existing samples? Don't know of any... but I can write one off
the top of my head...

package require dde
# Launch Word by association
exec start foo.doc
# Insert some data
dde execute Winword System "I'm inserting text, lalalalalala {ENTER} A
new line of text.."
# Save the file
dde execute Winword System {[FileSave]}
# Print the beastie
dde execute Winword System {[FilePrint]}
# Exit Word
dde execute Winword System {[FileExit]}

Note that the square brackets are used by Word to define commands,
so you need to make sure you escape them/enclose them in curly braces
so that Tcl doesn't get to them first and get confused.

Have fun!

-Bill
(Who spends wayyyy too much time using Tcl for Windows functions..)


Adrian Davis

unread,
Jun 17, 1999, 3:00:00 AM6/17/99
to
Thanks,

I've tried out a few simple things - Works OK...

...Just a couple of questions however...

(*) The document only seems to be updated if the Winword window is minimised
(Word97/NT4 SP3). Is this the correct behaviour -or- is there something I
can do to update the document while the window is visible?

(*) Is it possible to "FileExit" on an unsaved document and either
supress -or- "answer" the "Do you want to save it" dialog?

I'll get hold of some Word Macro Language documentation ASAP (Honest!!)

Many Thanks,
=Adrian=


Bill Schongar

unread,
Jun 17, 1999, 3:00:00 AM6/17/99
to
Adrian Davis wrote:

>I've tried out a few simple things - Works OK...
>...Just a couple of questions however...
>
>(*) The document only seems to be updated if the Winword window is
minimised
>(Word97/NT4 SP3). Is this the correct behaviour -or- is there something I
>can do to update the document while the window is visible?


Yup, use the 'Insert' command, instead of passing just ASCII. Helps
if you add -async, too, just for speed..

dde execute -async Winword System {[Insert "Hello, World."]}

>(*) Is it possible to "FileExit" on an unsaved document and either
>supress -or- "answer" the "Do you want to save it" dialog?


Yup.

dde execute Winword System {[FileExit 2]}

I would recommend, though, that you close the file first, then exit:

dde execute Winword System {[FileClose 2]}

(2 = close without saving, 1 = save first, 0 = prompt)

>I'll get hold of some Word Macro Language
>documentation ASAP (Honest!!)

Heh.. that's what I said originally too.. but I had it on my system all
along..
"wrdbasic.hlp"... installs if you choose the "please flood my hard drive
with all the stuff I may never use" options.. : )

-Bill

Adrian Davis

unread,
Jun 18, 1999, 3:00:00 AM6/18/99
to
Bill Thanks...

...Just one last time...

dde execute Winword System "This is line 1{ENTER}This is line 2"

...Gives...

This is line 1
This is line 2

...However...

dde execute -async Winword System {[Insert "This is line 1{ENTER}This is
line 2"]}

...Gives...

This is line 1{ENTER}This is line 2

I've had a look through the on-line documentation and I'm guessing that the
"{ENTER}" bit is one of the SendKeys codes. I presume these don't work with
Insert (A WordBasic command?) , so, is there another way of achieving the
same effect with Insert?

Which version of Word have you tried this with? Word97 seems to have the
"new" all-singing-all-dancing "Word Visual Basic" in place of "WordBasic".
I've only been able to have a quick look at this, but again, I'm guessing
your examples are using "WordBasic". Word97 automatically converts this into
"Word Visual Basic", but is there a way of using the "new" stuff?

I was getting a bit excited about the possibilities of this, yet I think I
may have to drop the idea unless I can find some real world examples of how
this can be made to work. To be useful I will need to be able to control the
layout of the document, and apply attributes such as fonts/bold/italic and
maybe mailmerge. A shame, but just I don't think have time to work all this
out from scratch, at least for a while.

Many thanks for all the help,
=Adrian=


Bill Schongar

unread,
Jun 18, 1999, 3:00:00 AM6/18/99
to
Adrian Davis wrote:

>...Just one last time...
>
>dde execute Winword System "line 1{ENTER} line 2"

vs.
>dde execute -async Winword System {[Insert "line 1{ENTER}line 2"]}

When you specify 'Insert', you're no longer in a command-parsing
mode, so {ENTER} is no longer a command. Gotta move to the
actual editing and positioning commands:

dde execute Winword System {[Insert "line 1"]}
dde execute Winword System {[InsertBreak.Type = 6]}
dde execute Winword System {[Insert "line 2"]}

>I was getting a bit excited about the possibilities of this...
...
Well, let's put it this way - there are more functions in there than
nature intended. While that's good, it does mean that you'll need
some upfront time to get a handle on it all.

When in doubt, look for the following classes of functions:

Insert
Format
File

They cover lots of ground. Also, consider using document
templates, rather than doing it all dynamically. Saves a lot of effort.

I think you'll be suprised at how far you can get with just poking
around with commands that sound interesting. Now that you
know how to send a command, you can send _any_ command.
No new syntax, just additional arguments and command names.

Good hunting..

-Bill


Kano

unread,
Jun 19, 1999, 3:00:00 AM6/19/99
to
Bill Schongar <bi...@lcdmultimedia.com> wrote in message
news:3768...@News.Destek.net...

> Adrian Davis wrote:
>
> >Is it possible using the "DDE" features of 8.1.1 and MS Word97 to:-
>
>
> Yup, you sure can. You just have to figure out the mysteries of
> Word's Macro language (WordBasic). You do have to do one
> other thing first, though..
>
> Have fun!
>
> -Bill
> (Who spends wayyyy too much time using Tcl for Windows functions..)

Where did you find all this stuff out? Is there a way to manipulate IE? My IRC
script has a function to retrieve the URL from netscape but not from IE. =)

-kl

Bill Schongar

unread,
Jun 22, 1999, 3:00:00 AM6/22/99
to
Kano wrote:
>Where did you find all this stuff out?

I was bashed on the head, and woke up with vast
piles of odd Windows knowledge? ; )

Seriously, though.. a lot of reading. When in doubt,
hunt down the reference material (be it a web site,
manual, or user group) for the product in question,
and look/search for keywords. You'll have to sift
through lots of useless garbage, but you will eventually
find what you need, or pointers to it. Be prepared
to dig, though, lots of the answers don't come easily...

... unless you ask and someone give them to you. : )

>Is there a way to manipulate IE?

Yup. Which version, and what specifically do you want to
manipulate? I will warn you ahead of time - IE doesn't
always like to play nice, and will often give you errors,
even when it carries out the command successfully.

The Server Name is 'IEXPLORE', and it accepts (for
the most part) the same data as Netscape. If all you want is the
URL, try this:

package require dde
set browser_data [dde request IEXPLORE WWW_GetWindowInfo 0xFFFFFFFF]
set url [lindex [split $browser_data ","] 0]

The "0xFFFFFFFF" tells the browser to use the last active window.

If you're using Netscape instead of IE, just switch the server name
to NETSCAPE instead of IEXPLORE.

Have fun..

-Bill


0 new messages