如何将文本从同一格式的文档复制到另一文档?

时间:2020-01-24 07:43:41

标签: vba ms-word

我有这段代码可以将一些文本从一个文档复制到新文档中。

For Each rng In docSource.SpellingErrors
   docNew.Range.InsertAfter rng.text & vbCr
Next

这不是复制源格式。

我正在尝试以下行,但出现错误

期望的函数或变量

docNew.Range.InsertAfter rng.PasteAndFormat(wdPasteDefault) & vbCr

我该怎么做?预先感谢。

下面有错误的测试文本。

When you create a Microsoft Word document for other people to read , it's important to spot and correct any speling mistakes

or gramatical errors you've made. You can let Word's spelling and grammmar

checkers suggest corrections automaticaly while you working , or you can check the spelling and gramar in the the file all 

at once when you're finishes writing your document . Microsoft Word 2010 come with some dictionary of standardd grammar and spellings, but they are not comprehensive.

1 个答案:

答案 0 :(得分:1)

要将内容从一个Word文档传输到另一个Word文档,通常最好使用Range.FormattedText而不是剪贴板。

像这样

Set docNewRange = docNew.Content
For Each rng In docSource.SpellingErrors
   docNewRange.FormattedText = rng.FormattedText 
   docNewRange.Collapse wdCollapseEnd
   docNewRange.InsertAfter vbCr
   docNewRange.Collapse wdCollapseEnd
Next