Microsoft KB Archive/58367

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 17:57, 18 July 2020 by 3155ffGd (talk | contribs) (importing KB archive)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


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


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