Automatically display image from URL?

Calligo

New Member
Joined
Aug 12, 2008
Messages
4
Hi,

I am creating a spreadsheet with various statistics for all the different banner ads that we use.

One of the fields in the spreadsheet contains the URL for the actual banner image.

Is there a way of making excel automatically display the picture that the URL refers to?
Ideally I'd like to have a thumbnail in the adjacent cell that can be enlarged by clicking on it or doing a mouseover.

Thanks in advance for your help.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
This is not really a finished job, but hopefully will give you some ideas.
One of the problems we have is that clicking a picture to run its macro does not select it, so we have to use indirect methods to find which one is active.
Here are 2 basic macros.The first one adds a picture into a cell containing a file name, resizes the picture to fit the cell, gives it a name, and assigns a macro. The second one runs via the Picturex_Click() event to toggle the picture size small <> large. We set the picture name via the _Click macro and find its matching cell by checking their top/left properties (which do not change).
Code:
'=============================================================================
'- MACRO 1 : TO ADD A PICTURE TO WORKSHEET.
'- INSERTS INTO ACTIVE CELL (CELL CONTAINING FILE NAME.) RESIZES TO CELL SIZE.
'- Brian Baulsom August 2008
'=============================================================================
Sub ADD_PICTURE_TO_SHEET()
    Dim MyPictureFolder As String
    Dim MyCell As Range
    Dim MyPictureFile As String
    Dim MyPictureName As String
    '------------------------------------------------------------------------
    '- initialise variables
    MyPictureFolder = "F:\"
    Set MyCell = ActiveCell             ' cell contains "test.jpg"
    MyPictureFile = MyPictureFolder & MyCell.Value
    MyPictureName = "Picture" & CStr(ActiveSheet.Pictures.Count + 1)
    '------------------------------------------------------------------------
    '- get picture
    ActiveSheet.Pictures.Insert(MyPictureFile).Select
    '- fit picture to cell
    With Selection
        .Top = MyCell.Top
        .Left = MyCell.Left
        .Height = MyCell.Height
        .Width = MyCell.Width
        .Name = MyPictureName                       ' rename
        .OnAction = MyPictureName & "_Click"        ' assign macro
    End With
End Sub
'=============================================================================
Code:
'=============================================================================
'- PICTURE CLICK EVENT (rightclick picture. Assign macro)
'- Get picture name & run resize macro
'=============================================================================
Dim PictureName As String
'-----------------------------------------------------------------------------
Sub Picture1_Click()
    PictureName = "Picture1"
    RESIZE_PICTURE
End Sub
'-----------------------------------------------------------------------------
Sub Picture2_Click()
    PictureName = "Picture2"
    RESIZE_PICTURE
End Sub
'=============================================================================
'- MACRO 2 : TO RESIZE PICTURE
'- Toggle size depending on whether it has been enlarged or not
'- Brian Baulsom August 2008
'=============================================================================
Sub RESIZE_PICTURE()
    Dim MyPicture As Object
    Dim MyTop As Double
    Dim MyLeft As Double
    Dim MyHeight As Double
    Dim MyCell As Range
    Dim EnlargedHeight As Double
    Dim EnlargedWidth As Double
    '--------------------------------------------------------------------------
    EnlargedHeight = 200
    EnlargedWidth = 200
    Set MyPicture = ActiveSheet.Pictures(PictureName)
    '--------------------------------------------------------------------------
    '- find the cell containing the picture
    With MyPicture
        MyTop = .Top
        MyLeft = .Left
        MyHeight = .Height
    End With
    '--------------------------------------------------------------------------
    '- check if top/left same as cell
    For Each MyCell In ActiveSheet.UsedRange
        If MyCell.Top = MyTop And MyCell.Left = MyLeft Then
            '-------------------------------------------------------------------
            '- picture taller than cell. resize to cell
            If MyHeight > MyCell.Height Then
                With MyPicture
                    .Height = MyCell.Height
                    .Width = MyCell.Width
                End With
            '--------------------------------------------------------------------
            Else
            '--------------------------------------------------------------------
                '- enlarge picture
                With MyPicture
                    .Height = EnlargedHeight
                    .Width = EnlargedWidth
                End With
            '--------------------------------------------------------------------
            End If
        End If
    Next
    '----------------------------------------------------------------------------
End Sub
'-----------------------------------------------------------------------------
 
Upvote 0
Hi Brian
Thanks for your help, however after considering the problem for a while I decided to bite the bullet and download all the images manually, as it would make everything else so much easier. Sorry for wasting your time!
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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