Insert Images to Excel Linked Word Table

Landshark24

New Member
Joined
Oct 27, 2019
Messages
6
I have a VBA code that copies a seelction of cells from Excel and creates a Word table that is linked to the original document. I need to be able to insert images into the created word table. The table will allow me to do this, but each time the link to excel is refreshed the images disappear. Is there a way to keep the images without dropping the link to the excel file?

Thank you
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
try this method
- amend to integrate with your existing code

Code:
Sub LinkedChartInWordTable()
   [COLOR=#008080][I] 'ensure Microsoft Word is referenced: see VBA \ Tools \ references[/I][/COLOR]
    Dim W As Word.Application, wDoc As Word.Document, wRng As Word.Range, wTbl As Word.Table
    Set W = CreateObject("Word.Application")
    W.Visible = True
    Set wDoc = W.Documents.Add
    
    With wDoc
        Set wRng = .Range(Start:=0, End:=0)
        Set wTbl = .Tables.Add(Range:=wRng, NumRows:=2, NumColumns:=2)
       [COLOR=#006400] 'insert images in table[/COLOR]
[COLOR=#ff0000]            With ThisWorkbook
                .Activate
                .Sheets("NameofSheet").Activate
                .ActiveSheet.ChartObjects(1).Select
            End With
            ActiveChart.ChartArea.Copy
            wTbl.Cell(1, 1).Range.PasteSpecial link:=True
            'etc
   [/COLOR] End With
End Sub
 
Last edited:
Upvote 0
@Yongle - thank you for your reply. I am assuming this code copies the picture from excel and pastes or inserts into the word table, but my excel doc doesnt have any images, I need to insert them directly to the word doc later, but the data from the excel doc still needs to update as changed even after the images have been inserted... Any other thoughts?
 
Upvote 0
Why are you updating links ?
What is being updated ?

Should the images in the table be static after being embedded ( ie the exact same image) ?
 
Upvote 0
The data that is updated manually in the original excel file needs to update in the word doc. But yes the images once inserted need to remain static.
 
Upvote 0
Hard Code one line for each static image (as in example below) so that the images are re-introduced every time the table is created

Code:
Sub LinkedChartInWordTable()
    'ensure Microsoft Word is referenced: see VBA \ Tools \ references
    Dim W As Word.Application, wDoc As Word.Document, wRng As Word.Range, wTbl As Word.Table
    Set W = CreateObject("Word.Application")
    W.Visible = True
    Set wDoc = W.Documents.Add
    
    With wDoc
        Set wRng = .Range(Start:=0, End:=0)
        Set wTbl = .Tables.Add(Range:=wRng, NumRows:=2, NumColumns:=2)
        'insert images in table
            With ThisWorkbook
                .Activate
                .Sheets("NameofSheet").Activate
                .ActiveSheet.ChartObjects(1).Select
            End With

            [COLOR=#ff0000]wTbl.Cell(1, 2).Range.InlineShapes.AddPicture "C:\Test\subfolder\Pic09.jpg"[/COLOR]

    End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,575
Messages
6,173,148
Members
452,503
Latest member
AM74

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