VBA:从 Excel 复制为图像并粘贴到 Word

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43146052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 12:22:52  来源:igfitidea点击:

VBA: Copy As Image from Excel and Paste into Word

excel-vbavbaexcel

提问by user7459948

I'm copying a range of cells from Excel as a picture and then pasting into a word document. It pastes at the beginning of the document, how could I set it to paste in a specific area? The area could be denoted by some text that I'd later find/replace.

我正在将 Excel 中的一系列单元格复制为图片,然后粘贴到 Word 文档中。它粘贴在文档的开头,如何将其设置为粘贴到特定区域?该区域可以由我稍后找到/替换的一些文本表示。

Thanks!

谢谢!

Range("A1:H5").Select
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture



Set objWord = CreateObject("Word.Application")

Set objDoc = objWord.Documents.Open("MyFile.docx")

objWord.Visible = True

Set objSelection = objWord.Selection

objSelection.Paste


End Sub

回答by Michel Fuche

I just came accross the same problem and used the following code. I use a bookmark called "here" which is saved in my Word document. HTH, Mitch.

我刚刚遇到了同样的问题并使用了以下代码。我使用一个名为“here”的书签,它保存在我的 Word 文档中。HTH,米奇。

Dim WordApp As Word.Application
Dim WordDoc As Word.Document

Set WordApp = New Word.Application
Set WordDoc = WordApp.Documents.Open("MyFile.docx")

Range("A1:H5").Select
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
WordApp.Visible = True
WordApp.ActiveDocument.Bookmarks("here").Select
Set objSelection = WordApp.Selection
objSelection.Paste