Excel 2010 VBA: Insert Image into cell comment

pujo

Well-known Member
Joined
Feb 19, 2009
Messages
710
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
I found this be searching the forum vba by VoG:
The line "ShapeRange.Fill" gives an error"Application-defined or object-defined error"
I did change the directory to one of my own, and still receive the error.
However, rather than open a directory, I would like to logic to open the folder dialog so that I could choose which image I want rather than auto selecting.
Can anyone assist me with this task?
Thanks,
Pujo
Code:
Sub yetanothe()Dim i As LongFor i = 10 To 100    With Range("B" & i)        .AddComment        .Comment.Text Text:="Owner:" & Chr(10) & ""        .Comment.ShapeRange.Fill.UserPicture "C:\Users\Owner\Pictures\IRUS Diagrams\40" & i - 9 & ".jpg"    End WithNext iEnd Sub</PRE>
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Code:
Sub AddImageToComment()
Dim myImage As Variant, myCell As Range


Set myCell = Range("A1") ' ---- [change the cell in which you wish to add the comment]
myImage = Application.GetOpenFilename("Images, *.jpg", , "Select a picture", , 0)


If Not TypeName(myImage) = "Boolean" Then
    If myCell.Comment Is Nothing Then
        myCell.AddComment
    End If
    With myCell.Comment
        .Shape.Fill.UserPicture PictureFile:=myImage
        .Visible = True
    End With
End If
End Sub
 
Upvote 0
That works great. Thanks!
How do I incorporate this bit into the procedure?
Code:
For i = 10 To 100
    With Range("B" & i)
Next i
 
Upvote 0
That works great. Thanks!
How do I incorporate this bit into the procedure?
Code:
For i = 10 To 100
    With Range("B" & i)
Next i




Code:
Sub AddImageToComment()
Dim myImage As Variant, myCell As Range, rng As Excel.Range
Set myCell = Range("b10:b100") ' ---- [change the cell in which you wish to add the comment]
myImage = Application.GetOpenFilename("Images, *.jpg", , "Select a picture", , 0)
If Not TypeName(myImage) = "Boolean" Then
    For Each rng In myCell.Cells
        If rng.Comment Is Nothing Then
            rng.AddComment
        End If
        With rng.Comment
            .Shape.Fill.UserPicture PictureFile:=myImage
            .Visible = True
        End With
    Next rng
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,222,405
Messages
6,165,864
Members
451,988
Latest member
boo203

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