How to Use DDEExecute from Word for Windows to ExcelLast reviewed: November 4, 1994 |
The information in this article applies to:
SUMMARYThe 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:
When run, this macro puts the formula "=B1" in the cell named "test". MORE INFORMATIONThe Microsoft Word for Windows macro code is as follows: Declare Function IsAppLoaded Lib "kernel"(name$) As Integer Alias "GetModuleHandle" Sub MAIN If IsAppLoaded ("EXCEL") = 0 Then Shell "EXCEL.EXE" ExecuteString$ = "=B1{enter}" ChanNum = DDEInitiate("EXCEL", "C:\WINDOWS\SHEET1.XLS") DDEExecute ChanNum, "[App.Restore()][Formula.Goto( " + Chr$(34) + "test" + Chr$(34) + ")]" DDEExecute ChanNum, ExecuteString$ DDEExecute ChanNum, "[App.Minimize()]" 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 "system" 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("test") |
KBCategory: kbinterop Last reviewed: November 4, 1994 |