I have recorded the following macro to add a picture to the comment field for a cell. However, I notice that if I delete the initial comment and re-run the macro I get errors on every line of code.
Why is that?
How can this macro be altered so that I will give me the option to insert a picture no matter which cell I have selected?
Sub AddPictureToCommentBox()
'
' AddPictureToCommentBox Macro
'
Range("B18").Select
Range("B18").AddComment
Range("B18").Comment.Visible = False
Range("B18").Comment.Text Text:="" & Chr(10) & ""
Selection.ShapeRange.Fill.Transparency = 0#
Selection.ShapeRange.Line.Weight = 0.75
Selection.ShapeRange.Line.DashStyle = msoLineSolid
Selection.ShapeRange.Line.Style = msoLineSingle
Selection.ShapeRange.Line.Transparency = 0#
Selection.ShapeRange.Line.Visible = msoTrue
Selection.ShapeRange.Line.ForeColor.RGB = RGB(0, 0, 0)
Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
Selection.ShapeRange.Fill.Visible = msoTrue
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(255, 255, 255)
Selection.ShapeRange.Fill.BackColor.RGB = RGB(255, 255, 225)
Selection.ShapeRange.Fill.UserPicture _
"C:\Users\Tony\Pictures\Becca's Art\My Birthday Parrot b 4-16-09.png"
----------------------------------------------------------------------------------------------------
I came across this macro which looks like it should do what I want but doesn't go any further than to add a comment box - there is no prompt to select an image. so essentially i'm left with an empty message box.
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
Bookmarks