Microsoft KB Archive/58367

{| = How to Use DDEExecute from Word for Windows to Excel =
 * width="100%"|

Last reviewed: November 4, 1994

Article ID: Q58367 The information in this article applies to:
 * Microsoft Excel for Windows, version 2.0
 * Microsoft Word for Windows, version 1.0

SUMMARY
The following is a macro for Word for Windows that sends commands to Microsoft Excel by way of dynamic data exchange (DDE). This macro makes the following assumptions:


 * 1) The worksheet &quot;SHEET1.XLS&quot; exists and is in the C:\WINDOWS directory.
 * 2) There is a cell on this worksheet that has previously been given the name &quot;test&quot; using Formula, Define Name.

When run, this macro puts the formula &quot;=B1&quot; in the cell named &quot;test&quot;.

MORE INFORMATION
The Microsoft Word for Windows macro code is as follows:

Declare Function IsAppLoaded Lib &quot;kernel&quot;(name$) As Integer Alias &quot;GetModuleHandle&quot; Sub MAIN If IsAppLoaded (&quot;EXCEL&quot;) = 0 Then Shell &quot;EXCEL.EXE&quot; ExecuteString$ = &quot;=B1{enter}&quot; ChanNum = DDEInitiate(&quot;EXCEL&quot;, &quot;C:\WINDOWS\SHEET1.XLS&quot;) DDEExecute ChanNum, &quot;[App.Restore][Formula.Goto( &quot; + Chr$(34) + &quot;test&quot; + Chr$(34) + &quot;)]&quot; DDEExecute ChanNum,  ExecuteString$ DDEExecute ChanNum, &quot;[App.Minimize]&quot; DDETerminate ChanNum End Sub When run, this macro checks to see if Microsoft Excel is already running. If it isn't, it starts Microsoft Excel. If it is not known what sheet(s) are currently open when Microsoft Excel is loaded, use &quot;system&quot; as the second parameter of the DDEInitate command. You can then issue a Microsoft Excel OPEN command using DDEExecute to open a specific file. Also, the Formula.Goto statement in the above DDEExecute statement is the equivalent of the following Microsoft Excel macro statement: =FORMULA.GOTO(&quot;test&quot;)
 * }