Newsgroups: comp.os.ms-windows.misc
Subject: Re: WinWord 2.0 DDE Commands
From: alistair@myrddn.mits.com.au
Date: 22 Jan 93 10:08:31 +1000
Nntp-Posting-User: alistair

In article <431@zam103.zam.kfa-juelich.de>, 
vell@zelux8.zel.kfa-juelich.de (jochen vell zel/ne ++492461612335) writes:

>Can anyone tell us where to find the Command-List to Control Winword via DDE ??
>Thanks in advance !!

Using the executeCommand instruction, you can send lines of WinBasic,
which allow you to do anything.

I've included an example file below.  It is written in Smalltalk/V for
Windows, but you should be able to figure it out without knowing
Smalltalk.

Hope this helps.

Thanks,

Alistair Grant

Internet:     alistair@mits.com.au
Alternate:    alistair%mits.com.au@ucsvc.ucs.unimelb.edu.au
---------------------------------------------------------------------------
To execute commands in MS Excel or Word from Smalltalk is fairly
straight-forward.  To open the connection, use:

<var> := DDEClient
	newClient: self
	application: '<executable name>'
	topic: '<a String>'.

The executable must reside in your path.  An example to connect to MS
Word is:

msWord := DDEClient 
	newClient: self 
	application: 'winword' 
	topic: 'Document 1'.

The result will be nil if the connection was not established.  If you
want to start the application from smalltalk try:

KernelLibrary winExec: 'winword' cmdShow: SwShownormal.

To send the command use:

<client> executeCommand: '[<command>]'.

For MS Word, <command>'s are WordBasic commands (see Help - WordBasic
Programming Language).

For MS Excel, <command>'s are Excel macros (see the Excel Users
Guide).

I've included a few examples below my sig.

Many thanks to the following people for all their help:

	Ron Schultz
	M. v. Loewis
	Rick (d88-rjo)

Hope you find this useful.

Thanks,

Alistair Grant

Internet:     alistair@mits.com.au
Alternate:    alistair%mits.com.au@ucsvc.ucs.unimelb.edu.au


------------------------ MS Word Example ------------------------------------
| msWord |

"establish a DDE link to MS-Word"

msWord := DDEClient newClient: self application: 'winword' topic: 'Document1'.

msWord isNil ifTrue:
    [self error: 'Start MS Word before executing me'].

"Insert the date and time"
msWord 
    executeCommand: '[InsertDateTime .DateTimePic = "d MMMM, yyyy"]';
    executeCommand: '[InsertPara]'.

"Insert some text"
msWord
    executeCommand: '[Insert "This will be a heading 1"]'.

"Set the current line style to 'heading 1'"
msWord
    executeCommand: '[StartOfLine]';
    executeCommand: '[FormatStyle .Name="heading 1"]'.

"Move down a line"
msWord
    executeCommand: '[EndOfLine][InsertPara]'.

"Select Courier 14 as the current font"
msWord
    executeCommand: '[Font "Courier", 14]'.

"Execute the InsertDateTime macro.  If the MS Word title bar starts flashing,
click on it, and then select the date format you want."
msWord
    executeCommand: '[ToolsMacro .Name="InsertDateTime", .Run]'.

"Select the current line"
msWord
    executeCommand: '[StartOfLine]';
    executeCommand: '[EndOfLine 1]'.

"Close the link"
msWord terminate.
---------------------------------------------------------------------------

Below are two examples of talking to Excel:

--------------------------- MS Excel Examples -------------------------------
| msExcel |

msExcel := DDEClient newClient: self application: 'excel' topic: 'Sheet1'.

msExcel isNil ifTrue:
    [self error: 'Start MS Excel before executing me'].

msExcel 
    executeCommand: '[FORMULA("=R1C1 + 2", "R1C2")]'.

msExcel
    executeCommand: '[FORMULA("1234", "R1C1")]'.

"Close the link"
msExcel terminate.
--------------------------- That's It ----------------------------------------
Xref: sparky comp.os.ms-windows.misc:6695 comp.os.ms-windows.setup:2960