Microsoft KB Archive/96946

-

{| The information in this article applies to: Microsoft Word for Windows, versions 1.0, 1.10, 1.10a, 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c
 * width="100%"|

SUMMARY
Dynamic data exchange (DDE) is a built-in feature of Microsoft Windows that allows two Windows applications to share data and send commands back and forth. A successful DDE process does the following:


 * Opens a communication channel between applications
 * Requests information from another application
 * Gives information to another application
 * Performs actions in another application
 * Closes the communication channel

In Word for Windows, these basic processes are implemented through the following WordBasic commands (the example at the end of this document shows how you can use these DDE commands to communicate between Word for Windows and Microsoft Excel for Windows): DDEInitiate   Opens a DDE channel from Word to another application ---   such as Microsoft Excel. A channel must be opened before and other DDE commands can be executed. The syntax for the DDEInitiate command is

ChanNum = DDEInitiate (App$, Topic$)

where ChanNum is a variable that contains the unique identification of the DDE channel, App$ is a string variable identifying the name of the application with which the link is established, and Topic$ is a              string variable identifying a specific object in App$ (for example, REVENUE.XLS in Microsoft Excel).

A special topic called &quot;system&quot; is also available for most DDE aware applications. The system topic can be              used to communicate in general with App$ when no               specific data file is desired.

DDERequest    Requests information from the connected application. --    Information must be returned in text string format and is immediately assigned to a text variable. The syntax of the DDEExecute command is

Result$ = DDERequest$ (ChanNum, Item$)

where Result$ is the string variable that will hold the returned information, ChanNum is a variable containing the unique DDE channel identification to a              specific application as assigned through DDEInitiate, and Item$ is a string variable containing the location of the information in that application (&quot;R1C1&quot; in the              application Microsoft Excel for example).

DDEPoke       Sends information to the connected application. The ---       syntax of the DDEPoke command is

DDEPoke ChanNum, Item$, Data$

where ChanNum is a variable containing the unique DDE channel identification to a specific application as              assigned through DDEInitiate, Item$ defines the destination location in that application (such as              &quot;R1C1&quot; in the application Microsoft Excel), and Data$ is the actual information to transfer.

DDEExecute    Runs a command in the connected application. The --    syntax for the DDEExecute command is

DDEExecute ChanNum, ExecuteString$

where ChanNum is a variable containing the unique DDE channel identification to a specific application as              assigned through DDEInitiate, and ExecuteString$ is a               specific command recognized by that application.

DDETerminate  Ends the conversation with the connected application. The syntax for the DDETerminate command is

DDETerminate ChanNum

where ChanNum is a variable containing the unique DDE channel identification to a specific application as              assigned through DDEInitiate.

A variation of this command available in Word for Windows is DDETerminateAll. This command, which has no arguments, will end conversations with all connected applications. This command is specific to              Word for Windows and a similar command may not be               available in other DDE aware applications. The syntax for the DDETerminateAll command is:

DDETerminateAll

To Use DDE to Connect Word for Windows and Microsoft Excel
The following example prompts for a number of days and then uses Microsoft Excel to add this number to today's date. The DDE conversation is initiated with the spreadsheet named &quot;Sheet1&quot;. Today's date is sent to Microsoft Excel using the DDEPoke command. The DDEExecute command is use to select and apply the &quot;m/d/yy&quot; format to the R1C2 cell. The result of today's date plus the specified amount of days is returned to Word for Windows with the DDERequest$ command.

Declare Function IsAppLoaded Lib &quot;kernel&quot;(name$) As Integer Alias &quot;GetModuleHandle&quot;

Sub Main days$ = InputBox$(&quot;How many days beyond today's date?&quot;) If IsAppLoaded(&quot;EXCEL&quot;) = 0 Then Shell &quot;Excel&quot; ChanNum = DDEInitiate(&quot;Excel&quot;, &quot;Sheet1&quot;) DDEPoke ChanNum, &quot;R1C1&quot;, Date$  'Put today's date in R1C1 '=== Calculate today's date + the number of days in R1C2 DDEPoke ChanNum, &quot;R1C2&quot;, &quot;=A1+&quot; + days$ DDEExecute ChanNum, &quot;[SELECT(&quot; + Chr$(34) + &quot;r1c2&quot; + Chr$(34) + &quot;)]&quot; DDEExecute ChanNum, &quot;[FORMAT.NUMBER(&quot; + Chr$(34) + \  &quot;m/d/yy&quot; + Chr$(34) + &quot;)]&quot; a$ = DDERequest$(ChanNum, &quot;R1C2&quot;) MsgBox a$, &quot;The date is &quot; + days$ + &quot; days away!&quot; DDETerminate ChanNum End Sub Reference(s): &quot;Using WordBasic&quot; by WexTech Systems and Microsoft
 * }

-

Last reviewed: July 30, 1997

© 1998 Microsoft Corporation. All rights reserved. Terms of Use.