51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 2929|回复: 1
打印 上一主题 下一主题

[Robot] DDEPoke的使用?

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2005-11-15 20:45:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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="[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

[ 本帖最后由 ilovejolly 于 2005-12-20 09:36 编辑 ]
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
发表于 2006-4-25 14:06:49 | 只看该作者
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="[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:
    MsgBox  Err & ": " & Error$   
End Sub

[ 本帖最后由 yangjingxiao 于 2006-4-25 14:09 编辑 ]
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-5-4 14:29 , Processed in 0.069724 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表