copy a picture from excel and paste into word

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
My code bellow works if you specify specific specific image names however I have 7 tabs some with 3 pictures on and i want them all to be copied over tot he word document

but the code has a type mismatch error on the thisworkbook.shapes line cans omeone help me please!

Code:
Sub recordme()
Dim appwd As Object
Dim shp As Shape
Dim sh As Worksheet
       Set appwd = GetObject(, "Word.Application")
       appwd.Visible = True
   appwd.Documents.Add
   For Each sh In Sheets
        For Each shp In ThisWorkbook.Shapes
        shp.Copy
       appwd.Selection.Paste
       Next shp
       Next sh
       
End Sub
 
Upvote 0
My code bellow works if you specify specific specific image names however I have 7 tabs some with 3 pictures on and i want them all to be copied over tot he word document

but the code has a type mismatch error on the thisworkbook.shapes line cans omeone help me please!

Code:
Sub recordme()
Dim appwd As Object
Dim shp As Shape
Dim sh As Worksheet
       Set appwd = GetObject(, "Word.Application")
       appwd.Visible = True
   appwd.Documents.Add
   For Each sh In Sheets
        For Each shp In ThisWorkbook.Shapes
        shp.Copy
       appwd.Selection.Paste
       Next shp
       Next sh
       
End Sub
did a bit of tinkering and this code sort of works, it pastes all the shapes into the word document, it doesn't resize though and does just paste pictures but all shapes i.e drop down boxes etc.
Code:
Sub recordme()
Dim appwd As Object
Dim shp As Shape
Dim sh As Worksheet
       Set appwd = GetObject(, "Word.Application")
       appwd.Visible = True
   appwd.Documents.Add
   For Each sh In Sheets
   sh.Activate
    For Each shp In ActiveSheet.Shapes
    shp.Copy
       appwd.Selection.Paste
    Next shp
    Next sh
        
        
      
       
       
End Sub
 
Upvote 0
I'm guessing that the reason for the lack of help on this thread is that it's not all that easy to do. U need to specify what the shape's name is that U R referring to in XL, copy it, and then paste it to some specific location in Word. So, U can just create/open any Word doc and paste the pic in there willy nilly (ie. at the current selection point which is likely the top of the doc) but I'm guessing that's not exactly what U want. To place a pic in a specific location, U either have to use a template with pic holders where U want them, or build the doc on the fly and insert the pic where U want it. After this, make sure to VBA clear your clipboard because it will overload and randomly cause your program to error.... grrrr. HTH. Dave
 
Last edited:
Upvote 0
IMHO, it's more likely that there's been a lack of input because: (a) it's a weekend; and (b) the question would have been better asked in the General Excel Discussion & Other Questions forum, as its not a strictly-Excel issue.

The following Excel macro will copy Excel shape objects other than those designated in the Select Case statement to the Word document. I've also included skeleton code for you to add any reformatting/resizing/repositioning of the shapes you might want to do in Word. Unless you take some action in that regard, you're liable to find all the shapes piled on top of each other. Since I don't know what you want to do in that regard, I haven't done anything.

Code:
Sub Demo()
Dim wdApp As New Word.Application
Dim wdDoc As Word.document, xlWkSht As Excel.Worksheet
Dim xlShp As Excel.Shape, wdRng As Word.Range, wdShp As Word.Shape
Set wdDoc = wdApp.Documents.Add
With ThisWorkbook
  For Each xlWkSht In .Worksheets
    For Each xlShp In xlWkSht.Shapes
      Select Case xlShp.Type
      ' Exclude these shapes:
      Case msoFormControl, msoOLEControlObject, msoEmbeddedOLEObject, msoLinkedOLEObject
      ' Copy any others:
      Case Else
        xlShp.Copy
        Set wdRng = wdDoc.Range
        wdRng.Collapse wdCollapseEnd
        wdRng.Paste
        ' Some Excel shapes are liable to end up pasted in-line in Word.
        ' The following ensures such objects are converted to floating shapes
        If wdRng.InlineShapes.Count > 0 Then
          Set wdShp = wdRng.InlineShapes(wdRng.InlineShapes.Count).ConvertToShape
        Else
          Set wdShp = wdRng.ShapeRange(wdRng.ShapeRange.Count)
        End If
        With wdShp
          ' You can reformat, resize and reposition the shape in Word here
        End With
      End Select
    Next
  Next
End With
wdApp.Visible = True
wdApp.Activate
Set wdApp = Nothing: Set wdDoc = Nothing: Set wdRng = Nothing: Set wdShp = Nothing
Set xlWkSht = Nothing: Set xlShp = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,809
Messages
6,174,759
Members
452,581
Latest member
ruby9c

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top