Microsoft KB Archive/58904

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Using DDE Macro to Send Commands from WinWord to Excel

PSS ID Number: Q58904 Article last modified on 06- 9-1992

1.00 1.10 1.10a 2.00 2.00a WINDOWS

Summary: The example below is a macro for Microsoft Word for Windows that sends commands to Microsoft Excel for Windows using dynamic data exchange (DDE). This macro makes the following assumptions: - The worksheet “SHEET1.XLS” exists and is located in the C: directory. - There is a cell on this worksheet that was previously named “test” using the Formula Define Name command.

Example

In the following routine, the text between the single angle brackets ( < and > ) should appear as one line without the single angle brackets. <Declare Function IsAppLoaded Lib “kernel”(name<math display="inline">) As Integer Alias "GetModuleHandle"> SUB MAIN IF IsAppLoaded("EXCEL") = 0 THEN SHELL "EXCEL.EXE" ExecuteString</math> = “=B1{enter}” ChanNum = DDEInitiate(“EXCEL”, “C:1.XLS”) <DDEExecute ChanNum, “[App.Restore()][Formula.Goto( " + Chr<math display="inline">(34) + "test" + Chr</math>(34) + ")]”> DDEExecute ChanNum, ExecuteString$ DDEExecute ChanNum, “[App.Minimize()]” DDETerminate ChanNum END SUB Running this macro places the formula “=B1” in the cell named “test.”

Additional reference words: w4wmacro 1.0 1.1 1.1a 2.0 2.0a 1.00 1.10 1.10a 2.00 2.00a