Pulling a Thumbnail from a link

anoop0085

New Member
Joined
Aug 4, 2022
Messages
9
Office Version
  1. 2016
Platform
  1. Windows
Dear guys ;

I would like to display a thumbnail from a url based on item code by clicking a button (vba) , take a note that i am using 2016 excel


 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
In case the problem is still open, try this macro:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'https://www.mrexcel.com/board/threads/pulling-a-thumbnail-from-a-link.1214203/
Dim PictName
Dim cPic As Shape, pLeft As Single, pTop As Single
'
If Target.Address = "$I$5" Then
    PictName = Application.VLookup(Range("I5").Value, Range("A1:B10000"), 2, False)
    If IsError(PictName) Then
        PictName = "D:\DImmagini\Moon_shot.jpg"                 '<<< A Default Image
    End If
    On Error Resume Next
        ActiveSheet.Shapes("Zczc_CPict").Delete
    On Error GoTo 0
    'Insert Picture:
        pLeft = Range("K3").Left
        pTop = Range("K3").Top
        Set cPic = ActiveSheet.Shapes.AddPicture(PictName, False, True, pLeft, pTop, True, True)
        With cPic
            .LockAspectRatio = msoFalse
            .Height = Range("K3").MergeArea.Height
            .Width = Range("K3").MergeArea.Width
    '        .Left = pLeft                                      'See message
    '        .Top = pTop
            .Name = "Zczc_CPict"
        End With
End If
End Sub
It has to be inserted into the vba class module of the worksheet:
-rightclick on the tab with the name of the sheet, select Display code; this will open the vba editor at the right position
-copy the code and paste it into the right "empty" frame of the vba editor; if that page already contains some code then publish it to check for possible compatibility problems.

The macro will excecute whenever cell I5 get changed
In case vlookupping I5 in the table A:B doesn't return any value then the macro will insert a default image; you have to insert the path and name of this default image, in the line marked <<< in the code above
Note that the inserted image will loose its H/W ratio, so it may appear distorted. If this is a problem then we need to set .LockAspectRatio = msoTrue but then you need to clarify wich size (Height or Width of the destination area) has to be set and thus we need to modify the instructions between the With /End With lines
Also, it could happens that the image does not center into the destination area after the resizing; if this happens then uncomment (ie remove the leading "apostrophe") on the two lines .Left= and .Top=

Try...
 
Upvote 0
Solution

Forum statistics

Threads
1,215,091
Messages
6,123,062
Members
449,089
Latest member
ikke

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