将文字和图片复制到新的word文档中

Copy text and picture into new word document

在活动的 word 文档中,我有一个从文档中提取文本字符串和所有图像的宏。 我想把这段文字和图片复制到一个新的空白word文档中。

我尝试了以下方法

Dim docNew As Document
Set docNew = Documents.Add

With ThisDocument    
                ...
                docNew.Content.Text = docNew.Content.Text & vbCrLf & sSentence
                For Each iShape In .InlineShapes
                    iShape.Select
                    Selection.CopyAsPicture
                    docNew.Content.Paste
                Next iShape
End With

当我执行此代码时,首先将文本正确复制到新的空白文档中。但是粘贴图片的时候会覆盖文字,文档中只剩下图片

我如何修改代码才能包含文本和所有图片?

正如您通过查看 the help text 会发现的那样 .Content 代表文档的整个主体。

假设要在文档末尾添加图片,替换

docNew.Content.Paste

   With docNew.Content
      .InsertParagraphAfter
      .Paragraphs.Last.Range.Paste
   End With