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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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