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 into A2

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

Sub InsertPic()
    Dim sPicPath As String
    With Sheet1
        sPicPath = “/blogpix/” & _
        .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

Posted in Uncategorized

2 thoughts on “Inserting Web Pictures

  1. 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:

    6) experiment by typing in A1 either TRUE or FALSE

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

  2. 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).

Posting code? Use <pre> tags for VBA and <code> tags for inline.

Leave a Reply

Your email address will not be published.