DDE related procedures in class Application (Word VBA)

This page presents procedures from class Application related to the theme DDE: DDEExecute, DDEInitiate, DDEPoke, DDERequest, DDETerminate and DDETerminateAll

DDEExecute

Sends a command or series of commands to an application through the specified dynamic data exchange (DDE) channel.

Syntax : expression.DDEExecute (Channel, Command)

Dim lngChannel As Long 
 
lngChannel = DDEInitiate(App:="Excel", Topic:="System") 
DDEExecute Channel:=lngChannel, Command:="[New(1)]" 
DDETerminate Channel:=lngChannel

Arguments

The following arguments are required:

Channel (Long) - The channel number returned by the DDEInitiate method.

Command (String) - A command or series of commands recognized by the receiving application (the DDE server). If the receiving application cannot perform the specified command, an error occurs.

DDEInitiate

Opens a dynamic data exchange (DDE) channel to another application, and returns the channel number.

If it is successful, the DDEInitiate method returns the number of the open channel. All subsequent DDE functions use this number to specify the channel.

Syntax : expression.DDEInitiate (App, Topic)

Dim lngChannel As Long 
 
lngChannel = DDEInitiate(App:="Excel", Topic:="System") 
DDEExecute Channel:=lngChannel, Command:="[OPEN(" & Chr(34) _ 
 & "C:\Sales.xls" & Chr(34) & ")] 
DDETerminate Channel:=lngChannel 
lngChannel = DDEInitiate(App:="Excel", Topic:="Sales.xls") 
DDEPoke Channel:=lngChannel, Item:="R1C1", Data:="1996 Sales" 
DDETerminate Channel:=lngChannel

Arguments

The following arguments are required:

App (String) - The name of the application.

Topic (String) - The name of a DDE topic—for example, the name of an open document—recognized by the application to which you are opening a channel.

DDEPoke

Uses an open dynamic data exchange (DDE) channel to send data to an application.

If the DDEPoke method isn't successful, an error occurs.

Syntax : expression.DDEPoke (Channel, Item, Data)

Dim lngChannel As Long 
 
lngChannel = DDEInitiate(App:="Excel", Topic:="System") 
DDEExecute Channel:=lngChannel, Command:="[OPEN(" & Chr(34) _ 
 & "C:\Sales.xls" & Chr(34) & ")] 
DDETerminate Channel:=lngChannel 
lngChannel = DDEInitiate(App:="Excel", Topic:="Sales.xls") 
DDEPoke Channel:=lngChannel, Item:="R1C1", Data:="1996 Sales" 
DDETerminate Channel:=lngChannel

Arguments

The following arguments are required:

Channel (Long) - The channel number returned by the DDEInitiate method.

Item (String) - The item within a DDE topic to which the specified data is to be sent.

Data (String) - The data to be sent to the receiving application (the DDE server).

DDERequest

Uses an open dynamic data exchange (DDE) channel to request information from the receiving application, and returns the information as a String.

When you request information from the topic in the server application, you must specify the item in that topic whose contents you are requesting. In Microsoft Office Excel, for example, cells are valid items, and you refer to them by using either the "R1C1" format or named references. Microsoft Excel and other applications that support DDE recognize a topic named "System." Three standard items in the System topic are described in the following table. Note that you can get a list of the other items in the System topic by using the SysItems item.

Syntax : expression.DDERequest (Channel, Item)

Dim lngChannel As Long 
 
lngChannel = DDEInitiate(App:="Excel", Topic:="System") 
DDEExecute Channel:=lngChannel, Command:="[OPEN(" & Chr(34) _ 
 & "C:\Documents\Book1.xls" & Chr(34) & ")]" 
DDETerminate Channel:=lngChannel 
lngChannel = DDEInitiate(App:="Excel", Topic:="Book1.xls") 
MsgBox DDERequest(Channel:=lngChannel, Item:="R1C1") 
DDETerminateAll

Arguments

The following arguments are required:

Channel (Long) - The channel number returned by the DDEInitiate method.

Item (String) - The item to be requested.

DDETerminate

Closes the specified dynamic data exchange (DDE) channel to another application.

Syntax : expression.DDETerminate (Channel)

Channel: The channel number returned by the DDEInitiate method.

Dim lngChannel As Long 
 
lngChannel = DDEInitiate(App:="Excel", Topic:="System") 
DDEExecute Channel:=lngChannel, Command:="[New(1)]" 
DDETerminate Channel:=lngChannel

DDETerminateAll

Closes all dynamic data exchange (DDE) channels opened by Microsoft Word.

This method does not close channels opened to Word by client applications. Using this method is the same as using the DDETerminate method for each open channel. If you interrupt a macro that opens a DDE channel, you may inadvertently leave a channel open. Open channels are not closed automatically when a macro ends, and each open channel uses system resources. For this reason, it is a good idea to use this method when you are debugging a macro that opens one or more DDE channels.

Dim lngChannel As Long 
 
lngChannel = DDEInitiate(App:="Excel", Topic:="System") 
DDEExecute Channel:=lngChannel, Command:="[OPEN(" & Chr(34) & _ 
 "C:\Documents\Book1.xls" & Chr(34) & ")]" 
DDETerminate Channel:=lngChannel 
lngChannel = DDEInitiate(App:="Excel", Topic:="Book1.xls") 
DDEPoke Channel:=lngChannel, Item:="R2C3", Data:="Hello World" 
DDEExecute Channel:=lngChannel, Command:="[Save]" 
DDETerminateAll