Welcome to Office Zealot Sign in | Join | Help

Excel: Code to add picture to Excel Comment

As you can see in the following image below, you can insert images as Excel comments.

Ok... so I am not sure of all the medicinal uses of this technology but it is cool. Imagine that you have a list of parts for a product and you want to assign them to cells... then your users could see them as they hover over the cells...  I dunno there must be something :s

Anyway, here is the code to do this in VBA (it assumes that the picture name comes from the cell text):

Sub AddPictureToComment()
    Dim rng As Range
    Dim shp As Comment
   
    Set rng = ActiveCell
   
    If Not rng.Comment Is Nothing Then
        rng.Comment.Delete
    End If
   
    If rng.Text <> "" Then
        Set shp = rng.AddComment("")
        shp.Shape.Fill.UserPicture rng.Text
    End If

End Sub

Published Monday, September 27, 2004 8:46 PM by charles

Comments

No Comments

Anonymous comments are disabled