Using VBA to embed existing linked images into Excel (2010)

Dunclair

New Member
Joined
Mar 10, 2016
Messages
2
I have an exising report generated in excel which has a thumbnail of a linked .jpg file inside the 1st cell of every row. There are 100's of rows each with a unique thumbnail and assosiated .jpg file. This excel file needs to be distributed to several other people. When distributed all the image links break and the thumbnails can no longer be viewed.

If possible i'd like to write a macro which looks at an existing image link and replaces the thumbnail with an embeded image... although if anyone has an alternative method of solving this problem i'll take any advice!

Many thanks
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Welcome to the Board

When hovering a thumbnail with the mouse, does it change to a hand and a path is displayed?
 
Upvote 0
See if this helps:

Code:
Sub hlink2()
Dim sh As Shape, i%, ws As Worksheet
Set ws = ActiveSheet
For i = 1 To ws.Shapes.Count
    InsertPicture ws.Shapes(i).Hyperlink.Address, ws.Shapes(i).TopLeftCell.Offset(, 4), 1, 1
Next
End Sub

Sub InsertPicture(fn$, TargetCell As Range, CenterH As Boolean, CenterV As Boolean)
Dim p As Object, t&, L&, w&, h&
If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
If Dir(fn) = "" Then Exit Sub
Set p = ActiveSheet.Pictures.insert(fn)
With TargetCell
    t = .Top
    L = .Left
    If CenterH Then
        w = .Offset(, 1).Left - .Left
        L = L + w / 2 - p.Width / 2
        If L < 1 Then L = 1
    End If
    If CenterV Then
        h = .Offset(1).Top - .Top
        t = t + h / 2 - p.Height / 2
        If t < 1 Then t = 1
    End If
End With
p.Top = t
p.Left = L
Set p = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,516
Messages
6,119,980
Members
448,934
Latest member
audette89

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