Applies To
Application Object.
Description
Runs a command or takes other actions in another application via the specified DDE channel.
Syntax
object.DDEExecute(channel, string)
object
Optional. The Application object.
channel
Required. The channel number returned by the DDEInitiate method.
string
Required. The message defined in the receiving application.
Remarks
The DDEExecute method is designed to send commands to another application. You can also use it to send keystrokes to an application, although the SendKeys method is the preferred way to send keystrokes. The string argument can specify any single key; any key combined with ALT, CTRL, or SHIFT, or any combination of those keys (in Windows); or any key combined with COMMAND, CTRL, OPTION, or SHIFT or any combination of those keys (on the Macintosh). Each key is represented by one or more characters, such as "a" for the character a, or "{ENTER}" for the ENTER key.
To specify characters that aren't displayed when you press the key, such as ENTER or TAB, use the codes shown in the following table. Each code in the table represents one key on the keyboard.
Key |
Code |
BACKSPACE |
"{BACKSPACE}" or "{BS}" |
BREAK |
"{BREAK}" |
CAPS LOCK |
"{CAPSLOCK}" |
CLEAR |
"{CLEAR}" |
DELETE or DEL |
"{DELETE}" or "{DEL}" |
DOWN ARROW |
"{DOWN}" |
END |
"{END}" |
ENTER (numeric keypad) |
"{ENTER}" |
ENTER |
"~" (tilde) |
ESC |
"{ESCAPE} or {ESC}" |
HELP |
"{HELP}" |
HOME |
"{HOME}" |
INS |
"{INSERT}" |
LEFT ARROW |
"{LEFT}" |
NUM LOCK |
"{NUMLOCK}" |
PAGE DOWN |
"{PGDN}" |
PAGE UP |
"{PGUP}" |
RETURN |
"{RETURN}" |
right ARROW |
"{RIGHT}" |
SCROLL LOCK |
"{SCROLLLOCK}" |
TAB |
"{TAB}" |
UP ARROW |
"{UP}" |
F1 through F15 |
"{F1}" through "{F15}" |
In Windows, you can also specify keys combined with SHIFT and/or CTRL and/or ALT. On the Macintosh, you can also specify keys combined with SHIFT and/or CTRL and/or OPTION and/or COMMAND. To specify a key combined with another key or keys, use the following table.
To combine with |
Precede the key code by |
SHIFT |
"+" (plus sign) |
CTRL |
"^" (caret) |
ALT or OPTION |
"%" (percent sign) |
COMMAND |
"*" (asterisk) |
Example
This example opens a channel to Word 6.0 for Windows, opens the Word document FORMLETR.DOC, and then sends the FilePrint command to WordBasic.
channelNumber = Application.DDEInitiate( _ app:="WinWord", _ topic:="C:\WINWORD\FORMLETR.DOC") Application.DDEExecute channelNumber, "[FILEPRINT]" Application.DDETerminate channelNumber
This example opens a channel to Word 6.0 for the Macintosh, opens the Word document Form Letter, and then sends the FilePrint command to WordBasic. On the Macintosh, you must use the Shell function to start Word, because the DDEInitiate method does not automatically start Word as it does in Windows. Also, because the Shell function is asynchronous, the macro may call the DDEInitiate method before Word has started. This example demonstrates how you can program around this by putting the DDEInitiate method call in a loop, testing channelNumber until it is no longer an error.
Shell "HD:Form Letter", 6 Do channelNumber = Application.DDEInitiate( _ app:="MSWord", _ topic:="HD:Form Letter") Loop Until TypeName(channelNumber) <> "Error" Application.DDEExecute channelNumber, "[FILEPRINT]" Application.DDETerminate channelNumber