DDEPoke的使用?
DDEPoke的语法如下,DDEPoke channel%, item$, data$
我创建了以下脚本,可是无法使用DDEPoke向word中写入testtext="Hello, world."
不知道什么原因?
还请高手能帮忙一下。
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 answer as String
Dim x as Integer
Dim path as String
appname="WinWord"
path="c:\msoffice\winword\"
topic="System"
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 Word."
Exit Sub
End If
DDEPoke channel, item, testtext
pcommand=""
DDEExecute channel, pcommand
pcommand=""
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
[ 本帖最后由 ilovejolly 于 2005-12-20 09:36 编辑 ] Microsoft Word does not support using the system topic to poke data. To enable Word to receive data, use the DDEPoke command, and send the data to a bookmark. You can either use a predefined bookmark or create your own.
以下代码测试通过
Sub main
Dim channel,x 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 answer as String
Dim path as String
appname="WINWORD"
path="D:\setupfiles\Office\OFFICE11\"
topic="C:\\doc1.doc"
item="\StartOfDoc"
testtext="Hello, world."
On Error Goto Errhandler
x=Shell(path & appname & ".EXE C:\\doc1.doc")
channel = DDEInitiate(appname, topic)
If channel=0 then
MsgBox "Unable to open Word."
Exit Sub
End If
DDEPoke channel, item, testtext
pcommand=""
DDEExecute channel, pcommand
pcommand=""
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:
MsgBoxErr & ": " & Error$
End Sub
[ 本帖最后由 yangjingxiao 于 2006-4-25 14:09 编辑 ]
页:
[1]