1

I am trying to copy an excel Table and image from MS EXCEL to MS WORD using VBA. I was struggling to find out how will I reference the tables and images into the Word once they are sent from excel. After a long research I came across a very simple answer for 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.Shading.BackgroundPatternColor = wdColorBlueGray

What I have done:
I am able to copy an image from excel and simply pasting it on to word doc. 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.

Community
  • 1
  • 1
geekay
  • 1,655
  • 22
  • 31
  • feel free to leave a comment or edit if you you think there is a better way to implemented the code that I have already written above. – geekay Jun 20 '11 at 13:06

1 Answers1

0

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.

Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
  • **para.range.PasteSpecial Link:=False, DataType:=wdPasteShape, Placement:=wdInLine, DisplayAsIcon:=False ... but is giving error – geekay Jun 23 '11 at 10:22
  • What error? Why are you copying a range of cells `Range("C1:D8")` instead of just the image? e.g. using `ActiveSheet.Shapes("Picture 2").Copy` or similar. I can see Word not wanting to paste a range of cells as a `wdPasteShape`. – Jean-François Corbett Jun 23 '11 at 10:41