如何在保留格式的同时使用 Visual Basic 将 HTML 格式的字符串插入到 Microsoft Word 文档中? [英] How do I insert HTML-Formatted Strings into a Microsoft Word Document using Visual Basic while preserving formatting?
问题描述
我使用 Visual Basic 和自动化接口从外部应用程序检索字符串.这些字符串包含简单的 html 格式代码(<b>、<i> 等).Visual Basic for Word 中有没有什么简单的函数可以将这些字符串插入到word 文档中,并将html 格式代码转换为word 格式?
I use Visual Basic and an automation interface to retrieve strings from an external application. These strings contain simple html formatting codes (<b>, <i>, etc.). Is there any easy function in Visual Basic for Word to insert these strings into a word document and convert the html formatting codes to word formatting?
推荐答案
这是使用 VB 将 HTML 添加到剪贴板的链接:
Here's a link to add HTML to the clipboard using VB:
http://support.microsoft.com/kb/274326
在剪贴板上有了 HTML 后,使用如下方式将其粘贴到您的 Word 文档中:
Once you have the HTML on the clipboard, paste it into your word doc using something like this:
ActiveDocument.Range.PasteSpecial ,,,,WdPasteDataType.wdPasteHTML
这几乎相当于您手动剪切和粘贴它.
This is pretty much the equivalent of you cutting and pasting it in manually.
这篇关于如何在保留格式的同时使用 Visual Basic 将 HTML 格式的字符串插入到 Microsoft Word 文档中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!