Excel 2010 VBA: Insert Image into cell comment

pujo

Well-known Member
Joined
Feb 19, 2009
Messages
708
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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
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,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

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