How to Use DDEExecute from Word for Windows to Excel

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 "SHEET1.XLS" exists and is in the C:\WINDOWS directory.

  2. There is a cell on this worksheet that has previously been given the name "test" using Formula, Define Name.

When run, this macro puts the formula "=B1" in the cell named "test".

MORE INFORMATION

The 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
KBSubcategory:

Additional Reference Words: 1.0 1.00 2.0 2.00


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 4, 1994
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.