Word 自动化:无需通过剪贴板即可编写 RTF 文本 [英] Word Automation: Write RTF text without going through clipboard

查看:25
本文介绍了Word 自动化:无需通过剪贴板即可编写 RTF 文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用存储在变量中的一些 RTF 字符串替换 Word (2003/2007) 中的当前选择.

I am trying to replace the current selection in Word (2003/2007) by some RTF string stored in a variable.

这是当前代码:

Clipboard.SetText(strRTFString, TextDataFormat.Rtf)
oWord.ActiveDocument.ActiveWindow.Selection.PasteAndFormat(0)

有没有办法在不通过剪贴板的情况下做同样的事情.或者有什么办法可以将剪贴板数据推送到安全的地方,然后再恢复?

Is there any way to do the same thing without going through the clipboard. Or is there any way to push the clipboard data to a safe place and restore it after?

推荐答案

将 RTF 放在文件中而不是剪贴板中,然后从文件中插入,例如

Put the RTF in a file instead of the clipboard, then insert from the file, e.g.

Selection.InsertFile FileName:="myfile.rtf", Range :="", _ConfirmConversions:=False, Link:=False, Attachment:=False

这篇关于Word 自动化:无需通过剪贴板即可编写 RTF 文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆