Macro: Insert Comment with Picture

screamer

New Member
Joined
Jun 10, 2009
Messages
7
Hi,

I've recently created a spreadsheet with the aim of recording errors in a product.

The easiest way to show these errors is sometimes with a picture and here is the problem. When I use autofilter the pictures do not get filtered. I would therefore like to add the pictures as a comment instead however do not want to go through the long process of clicking all the boxes each time. Idealy I don't want to collect the image from a separate file but would like to paste it directly into a comment.

I have tried various ways of recording Macro's but have had no success.

I have also found the below code after various searches but I don't have a great enough understanding to minipulate it.

Can any one help me?

Thank you,

Stephen

Code:
Sub PictureIntoComment()
[COLOR=#006600]'www.contextures.com\xlcomments03.html[/COLOR]
Dim ch As ChartObject
Dim dWidth As Double
Dim dHeight As Double
Dim ws As Worksheet
Dim sName As String
Dim cmt As Comment
Dim sPath As String
Dim sFile As String
Dim rng As Range
Set ws = ActiveSheet
Set rng = ActiveCell
sPath = ThisWorkbook.Path & "\"
sName = InputBox("Name for picture file (no extension)", "File Name")
If sName = "" Then sName = "Picture_" & Format(Date, "yyyymmdd")
sFile = sPath & sName & ".gif"
 
    dWidth = Selection.Width
    dHeight = Selection.Height
 
    Selection.Cut
    Set ch = ws.ChartObjects.Add(Left:=rng.Left, Top:=rng.Top, _
      Width:=dWidth, Height:=dHeight)
    ch.Chart.Paste
    rng.Activate
    ch.Chart.Export sFile
    ch.Delete
    Set cmt = rng.AddComment
    cmt.Text Text:=""
    With cmt.Shape
      .Fill.UserPicture sFile
      .Width = dWidth
      .Height = dHeight
    End With
 
End Sub
 
If you set the pictures' object positioning to "Move and size with cells" (Format|Picture|Properties tab) the pictures will follow the AutoFilter.
 
Upvote 0
Andrew,

Thanks for the quick reply.

Is there any way to set that as the default setting for all pictures?

Stephen
 
Upvote 0
No, "Move but don't size" appears to be the default. But you can use this to change the setting
for all the pictures on the active sheet:

Code:
ActiveSheet.Pictures.Placement = xlMoveAndSize
 
Upvote 0

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