Sends data to an application on an open dynamic-data exchange (DDE) channel.
DDEPokechannel%, item$, data$
where: | is: |
channel% | An integer or expression for the open DDE channel number. |
item$ | A string or expression for the name of an item in the currently opened topic. |
data$ | A string or expression for the information to send to the topic. |
If channel% doesn't correspond to an open channel, an error occurs.
When you open a channel to an application using DDEInitiate, you also specify a topic, such as a filename, to communicate with. The item$ is the part of the topic you want to send data to. DDEPoke sends data as a text string; you cannot send text in any other format, nor can you send graphics.
If the server application doesn't recognize item$, an error occurs.
This example opens Microsoft Write, uses DDEPoke to write the text "Hello, world" to the open document (Untitled) and uses DDEExecute to save the text to the file TEMP001.
Sub main
Dim channel as Integer
Dim appname as String
Dim topic as String
Dim testtext as String
Dim item as String
Dim pcommand as String
Dim msgtext as String
Dim x as Integer
Dim path as String
appname="WinWord"
path="c:\msoffice\winword\"
topic="Document1"
item="Page1"
testtext="Hello, world."
On Error Goto Errhandler
x=Shell(path & appname & ".EXE")
channel = DDEInitiate(appname, topic)
If channel=0 then
MsgBox "Unable to open Write."
Exit Sub
End If
DDEPoke channel, item, testtext
pcommand="[FileSaveAs .Name = " & _
Chr$(34) & "C:\TEMP001" & Chr$(34) & "]"
DDEExecute channel, pcommand
pcommand="[FileClose]"
DDEExecute channel, pcommand
msgtext="The text: " & testtext & _
" saved to C:\TEMP001." & Chr$(13)
msgtext=msgtext & Chr$(13) & "Delete? (Y/N)"
answer=InputBox(msgtext)
If answer="Y" or answer="y" then
Kill "C:\TEMP001.doc"
End If
DDETerminate channel
Exit Sub
Errhandler:
If Err<>0 then
MsgBox "DDE Access failed."
End If
End Sub