See Also Example
Sends a command string to the other application in a dynamic data exchange
Syntax
control.LinkExecute cmdstring
Remarks
The LinkExecute method has these parts:
Part Description
control Name of the Visual Basic control involved in a DDE conversation. The control can be any label, picture box, or text box.
cmdstring String expression containing a command recognized by the other application.
The actual value of cmdstring will vary depending on the source applications. For example, Microsoft Excel and Microsoft Word for Windows will accept command strings that consist of their macro commands enclosed by square brackets. To see what command strings a source application will accept, consult documentation for that application.
LinkPoke Method
LinkRequest Method
LinkSend Method
The example establishes a DDE link with Microsoft Excel, places some values into cells in the first row of a new worksheet, and charts the values. LinkExecute sends Microsoft Excel the command to activate a worksheet, select some values, and chart them. To try this example, Microsoft Excel must be installed and in your path. Paste the code into the Declarations section of a form that has a text box with the default name Text1. Then press F5 and click the form.
Sub Form_Click ()
Const NONE = 0, LINK_MANUAL = 2 ' Declare constants.
Dim Cmd, I, Q, Row, Z ' Declare variables.
Q = Chr(34) ' Define quote marks.
' Create a string containing Excel macro commands:
Cmd = "[ACTIVATE(" & Q &"SHEET1" & Q & ")]"
Cmd = Cmd & "[SELECT(" & Q & "R1C1:R5C2" & Q & ")]"
Cmd = Cmd & "[NEW(2,1)][ARRANGE.ALL()]"
If Text1.LinkMode = NONE Then
Z = Shell("Excel", 4) ' Start Excel.
Text1.LinkTopic = "Excel|Sheet1" ' Set link topic.
Text1.LinkItem = "R1C1" ' Set link item.
Text1.LinkMode = LINK_MANUAL ' Set link mode.
End If
For I = 1 To 5
Row = I ' Define row number.
Text1.LinkItem = "R" & Row & "C1" ' Set link item.
Text1.Text = Chr(64 + I) ' Put value in Text.
Text1.LinkPoke ' Poke value to cell.
Text1.LinkItem = "R" & Row & "C2" ' Set link item.
Text1.Text = Row ' Put value in Text.
Text1.LinkPoke ' Poke value to cell.
Next I
Text1.LinkExecute Cmd ' Execute Excel commands.
End Sub