Inserting Web Pictures

A question from Chris:

[W]hat I would like to do is paste (link) a web image into a cell, the choice of web image dependent on another cell.

Eg. A1=”image1”, paste http://web.com/image1.jpeg into A2

Here's a macro that uses the AddPicture method of Shapes collection object.

Sub InsertPic()
   
    Dim sPicPath As String
   
    With Sheet1
        sPicPath = "http://www.dicks-blog.com/blogpix/" & _
            .Range("A1").Value
   
        .Shapes.AddPicture Filename:=sPicPath, _
            LinkToFile:=msoTrue, _
            SaveWithDocument:=msoFalse, _
            Left:=.Range("A2").Left, _
            Top:=.Range("A2").Top, _
            Width:=180, Height:=156
    End With
   
End Sub

The end result looks like this:

Excel range showing name in A1 and picture in A2

2 Comments

  1. Rob van Gelder:

    I misread the question and was about to describe a different solution.

    My answer is sort of on the same lines, so I'll provide anyway.

    1) create a smiley face picture in mspaint, copy-paste to cell G1 so it occupies G1:I8

    2) create a frowny face picture in mspaint, copy-paste to cell J1 so it occupies J1:L8

    3) create a named range:
    name: mypic
    formula: =IF($A$1,$G$1:$I$8,$J$1:$L$8)

    4) copy-paste your smiley picture to cell A3

    5) highlight the new copy then from the formula bar type:
    =mypic

    6) experiment by typing in A1 either TRUE or FALSE

    you'll need to turn off gridlines for the effect to work right.

  2. doco:

    While we are talking of refedit again, I would like to refer to an old post concerning the usage of RefEdit (which I quit using altogether because it's tendency to lock things up).

Leave a comment