简体   繁体   English

使用VBA在MS Word中查找图像参考

[英]Finding Image reference in MS Word using VBA

I am trying to copy an excel Table and image from MS EXCEL to MS WORD using VBA. 我正在尝试使用VBA将Excel表和图像从MS EXCEL复制到MS WORD。 I was struggling to find out how will I reference the tables and images into the Word once they are sent from excel. 我试图找出将表格和图像从excel发送出去后如何将它们引用到Word中。 After a long research I came across a very simple answer for table : 经过长时间的研究,我遇到了一个非常简单的table答案:

 Range("C1:D8").Copy Dim WDDoc As Word.Document Dim table1 As Word.Table Dim para As Paragraph Set para = WDDoc.Paragraphs.Add para.Range.PasteSpecial Link:=False, DataType:=wdPasteRTF, Placement:=wdInLine, DisplayAsIcon:=False 

set table1 = WDDoc.Tables(1) ' getting reference for the Pasted tables in word 设置table1 = WDDoc.Tables(1)'以单词形式获取粘贴表的引用

table1.Shading.BackgroundPatternColor = wdColorBlueGray table1.Shading.BackgroundPatternColor = wdColorBlueGray

What I have done: 我做了什么:
I am able to copy an image from excel and simply pasting it on to word doc. 我可以从excel复制图像并将其粘贴到Word文档中。 para.

What I need? 我需要的?
after copying n picture i am not able to refer to that picture in word and hence not able to edit or resize the image once it is pasted. 复制n张图片后,我无法用文字引用该图片,因此一旦粘贴就无法编辑或调整其大小。

Try this 尝试这个

With ActiveDocument.InlineShapes(ActiveDocument.InlineShapes.Count)
    .Height = 314.95 ' or whatever
End With

This assumes that the picture is pasted "in line with text" (as you do) and is the last (furthest down) in-line picture in the document. 这假定图片被粘贴为“与文本一致”(如您所做的那样),并且是文档中最后一个(最向下的)嵌入式图片。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM