How to save / copy embedded image from Excel to Word

What I have : An Excel file in which in a column (in fact it is freely formatted, but aligned inside the column), some elements are embedded BMP images that show the formula =EMBED("Paint.Picture","")when you click on them. When you look at an Excel worksheet, only the icon representing the image is displayed, not the image.

What I want : An embedded image (not an icon) is copied to a new Word document.

The code I still have :

'Image Objects
Dim myObjs As Shapes
Dim myObj As Shape
Set myObjs = ActiveSheet.Shapes

'Traversing objects
Dim row As Integer
Dim myRange As Range
Dim myRange2 As Range
Dim isAddressMatch As Boolean

'Word Document Objects
Dim wordApp As New Word.Application
Dim myWord As Word.Document


'Prepare word for output
Set myWord = wordApp.Documents.Add
wordApp.Visible = True

'Initalize traversing objectts
Set myRange = Sheets("myWorksheet").Range("Q5")
Set myRange2 = Sheets("myWorksheet").Range("E5")
row = 0

'Loop through range values in the desired column
While (myRange2.Offset(row).Value <> "")
    'Loop through all shape objects until address match is found.
    For Each myObj In myObjs

        On Error Resume Next
        isAddressMatch = (myObj.TopLeftCell.Address = myRange.Offset(row).Address)
        If Err.Number <> 0 Then
            isAddressMatch = False
            On Error GoTo 0
        End If

        'When match is found copy the bmp picture from Excel to Word
        If (isAddressMatch) Then
            myObj.Select
            ''''''''This copies the excel default picture,'''''''''''''''
            ''''''''not the picture that is embeded.'''''''''''''''''''''
            myObj.CopyPicture 'What is the correct way to copy myObj

            myWord.Range.Paste
            'Rest of the code not yet implement

        End If
    Next
    row = row + 1
Wend

, : "", . , , (), .

: , , , .

+4
2

:

jspek, Copy OLEObject, :

Dim obj As OLEObject
Set obj = ActiveSheet.OLEObjects(myObj.Name)

'Copy the OLE object representing a picture.
obj.Copy
'Paste the picture in Word.
myWord.Range.Paste

, , SendKeys - . , , OLEObject. : -)

OLEObject. OLE ( ) , , , Word.

'Get the OLE object matching the shape name.
Dim obj As OLEObject
Set obj = ActiveSheet.OLEObjects(myObj.Name)

'Activate the OLE host application.
obj.Activate
'Send CTRL+A to select the picture in Paint and CTRL+C to copy it.
Application.SendKeys "^a"
Application.SendKeys "^c"
'Paste the picture in Word.
myWord.Range.Paste
+1

, , " " , . :

Excel Word 1. Excel, → Define NAME 2. "NAME" , . , # Word Excel, . NAME = Question_22 = WBT16DS058! $A $90 (= ! Cellrange) 3. Excel. 4. Word ( 022), . 5. Excel, , #NAME. (.. - R312Test.xlsx # Question_22). 6. , Excel .

NAME , , .

, "Define Name" , , , .

, .

0

Source: https://habr.com/ru/post/1618021/


All Articles