vba 复制 Excel 单元格并粘贴到 Word 中作为图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25373806/
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
Copy Excel Cells and Paste into Word as an Image
提问by Steve McDonald
I'm trying to capture an image of a range of cells. This image can either be saved, or pasted into the same excel document, pasted into a word document, etc. I just need to generate images from a groups of cells.
我正在尝试捕获一系列细胞的图像。这个图像可以保存,也可以粘贴到同一个excel文档中,粘贴到一个word文档中等等。我只需要从一组单元格中生成图像。
I thought I had figured it out by copying and pasting into word with this:
我以为我已经通过复制并粘贴到 word 中找到了它:
Dim objWord, objDoc As Object
ActiveWindow.View = xlNormalView
Range("A1:B45").Select
Selection.Copy
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add
objWord.Visible = True
objWord.Selection.PasteSpecial Link:=False, DataType:=wdPasteMetafilePicture, _
Placement:=wdInLine, DisplayAsIcon:=False
objWord.Selection.TypeParagraph
When I run this, it seems to work. But the object that's pasted in word is actually a spreadsheet object that acts like a metafile. (So it's bringing the data along with it as an embedded excel sheet).
当我运行它时,它似乎有效。但粘贴在 word 中的对象实际上是一个电子表格对象,其作用类似于元文件。(因此它将数据作为嵌入式 Excel 工作表一起提供)。
Any suggestions?
有什么建议?
回答by Gary's Student
This appears to work:
这似乎有效:
Sub luxation()
Dim objWord, objDoc As Object
ActiveWindow.View = xlNormalView
Range("A1:B45").Select
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add
objWord.Visible = True
objWord.Selection.Paste
objWord.Selection.TypeParagraph
End Sub