Syntax
DDEInitiate(Application$, Topic$)
Remarks
Initiates a dynamic-data exchange (DDE) conversation with an application and opens a DDE channel through which the conversation takes place. If DDEInitiate() is able to open a channel, it returns the number of the open channel, which is an integer greater than 0 (zero). (The first DDE channel Word opens during a session is channel 1, the second is channel 2, and so on.) All subsequent DDE instructions during the DDE conversation use this number to specify the channel. DDEInitiate() returns 0 (zero) if it fails to open a channel.
Note
In Word version 6.0 for Windows NT and Word version 7.0, you cannot depend on a program started with Shell to be finished loading before the instructions following the Shell statement in your macro are run. A DDEInitiate instruction that tries to communicate with an application that has not finished loading will generate errors. To avoid this problem, you can use a For...Next loop to delay the DDEInitiate instruction until the other application is loaded. For example:
If AppIsRunning("Microsoft Access") = 0 Then Shell "MSACCESS.EXE", 0 For i = 1 to 2000 x = i Next i End IF chan = DDEInitiate("MSAccess", "System")
Argument | Explanation | |
Application$ | The name used to specify an application that supports DDE as a DDE server. In Windows, this is usually the name of the application's .EXE file without the .EXE filename extension. If the application is not running, DDEInitiate() cannot open a channel and returns an error. | |
Topic$ | The name of a topic recognized by Application$. An open document is a typical topic. (If Topic$ is a document name, the document must be open.) If Application$ doesn't recognize Topic$, DDEInitiate() generates an error. Many applications that support DDE recognize a topic named System, which is always available and can be used to find out which other topics are available. For more information on the System topic, see DDERequest$(). |
The maximum number of channels that can be open simultaneously is determined by Microsoft Windows and your system's memory and resources. If you aren't using an open channel, you should conserve resources by closing the channel using DDETerminate or DDETerminateAll.
Examples
This example opens a channel to Microsoft Excel and the file SALES.XLS (Windows) or BLUE SKY SALES (Macintosh). The variable channel is assigned the channel number that is returned. If Microsoft Excel is not running or the file is not open, the function returns 0 (zero) and generates an error.
Here is the Windows version of the example:
channel = DDEInitiate("Excel", "C:\EXCEL\EXAMPLES\SALES.XLS")
And here is the Macintosh version:
channel = DDEInitiate("Excel", "HD1:EXCEL:EXAMPLES:BLUE SKY SALES")
The following example first ensures that Microsoft Excel is running, and then opens a channel to Microsoft Excel and the System topic and uses DDERequest$() to get the Topics item. The Topics item, a standard item in the System topic that is always available, is a list of available topics, including the names of open documents.
Here is the Windows version of the example:
If AppIsRunning("Microsoft Excel") = 0 Then Shell "C:\EXCEL\EXCEL.EXE" AppActivate "Microsoft Word", 1 End If channel = DDEInitiate("Excel", "System") topics$ = DDERequest$(channel, "Topics") If InStr(topics$, "Sheet1") <> 0 Then MsgBox "Sheet1 is an available topic." End If DDETerminate channel
And here is the Macintosh version:
If AppIsRunning(MacID$("XCEL")) = 0 Then Shell MacID$("XCEL") AppActivate MacID$("MSWD"), 1 End If channel = DDEInitiate("Excel", "System") topics$ = DDERequest$(channel, "Topics") If InStr(topics$, "Sheet1") <> 0 Then MsgBox "Sheet1 is an available topic." End If DDETerminate channel
See Also
DDEExecute, DDEPoke, DDERequest$(), DDETerminate, DDETerminateAll