Please Note: This article is written for users of the following Microsoft Excel versions: 2007 and 2010. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Moving Comment Background Pictures to Cells.

Moving Comment Background Pictures to Cells

Written by Allen Wyatt (last updated April 22, 2021)
This tip applies to Excel 2007 and 2010


4

Francois has a bunch of comments in a worksheet, and each comment contains a picture as a background. He would like to remove those background pictures from the comments and place them, instead, as graphics in the cells just to the right of where the comments are located.

The only way to do this is with the aid of a macro. The reason is that you cannot manually select and copy any graphic that has been stored in the background of a comment. You can, in a macro, approximate "grabbing" the image:

Sub CommentPictures()
    Dim cmt As Comment
    Dim rCell As Range
    Dim bVisible As Boolean

    For Each cmt In ActiveSheet.Comments
        With cmt
            bVisible = .Visible
            .Visible = True
            Set rCell = .Parent.Offset(0, 1)
            .Shape.CopyPicture _
              Appearance:=xlScreen, Format:=xlPicture
            rCell.PasteSpecial
            Selection.ShapeRange.LockAspectRatio = msoFalse
            Selection.Width = rCell.Width
            Selection.Height = rCell.Height
            .Visible = bVisible
            .Shape.Fill.OneColorGradient msoGradientFromCenter, 1, 1
        End With
    Next cmt
End Sub

The macro steps through each comment in the active worksheet. The entire comment (including the background) is copied as a graphic to the Clipboard, then it is pasted into the desired cell. The background of the comment is then set to a different fill instead of the graphic.

You should note that this approach provides only an approximation of grabbing the background picture. It also, in copying the entire comment as a graphic, copies any text that is contained in the comment.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11165) applies to Microsoft Excel 2007 and 2010. You can find a version of this tip for the older menu interface of Excel here: Moving Comment Background Pictures to Cells.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Deleting Blank Rows

Got some pesky blank rows in your data that you want to get rid of? This tip provides a wide variety of methods you can ...

Discover More

Making Pane Settings Persist

When you freeze panes in a worksheet, those panes should persist even though you save the workbook and reload it. There ...

Discover More

Turning Headers On and Off

Normally Excel displays row and column headers in a worksheet. If you prefer, you can turn these navigational aids off ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (ribbon)

Editing Comments and Notes

Comments and notes can be very helpful in a worksheet. After they are added, you may want to change what they contain. ...

Discover More

Formatting Text in Comment Boxes

Want to make your worksheet comments appear a certain way? It's easy to do using techniques you are already familiar with.

Discover More

Printing Formatted Comments

When you print your worksheet, you may want Excel to include your comments or notes as they appear on the screen. Here's ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 + 7?

2021-09-11 13:35:54

Kurt Müller

Attention: A "funny" thing with .LockAspectRatio = msoTrue is the following:

The standard shape of a comment is a rectangle. It shows four circles in each corners and four circels in each middle of the sides.

If .LockAspectRatio = msoTrue is used the AspectRatio is only locked, if the comment shape is drawn at the circles in the corners.

But the AspectRatio is easily destroyed, if the comment shape is drawn left or right, up or down at the circles in the middle of the sides.

So anybody else who is using the workbook together with others can destroy the AspectRatio of the background pictures easily. If the worksheets in the workbook have a large amount of comments with background pictures it is not affordable to rescue distorted AspectRatios for the pictures manually.

(see Figure 1 below)

Figure 1. comment shape


2021-07-18 05:25:23

Kurt Müller

To make sense to move comment background pictures to cells it is necessary to preserve the scale of the inserted user picture:

Sub insert_userpicture_in_comments()

Dim rngZelle As Range

Dim strFilename As Variant
Dim strFilter As String
Dim ScaleValue As Single
Dim ScaleValue2 As Single

Dim objPic As IPictureDisp
Dim Source As String

Dim i As Integer

If ActiveSheet.Comments.Count = 0 Then
MsgBox "No comments in entire sheet"
Exit Sub
End If

strFilter = "JPG Files (*.jpg), *.jpg" _
& ", GIF Files (*.gif), *.gif" _
& ", Bitmaps (*.bmp), *.bmp" _
& ", WMF Files (*.wmf), *.wmf"

strFilename = Application.GetOpenFilename(strFilter)

If strFilename = False Then GoTo LabelA

Source = (CStr(strFilename))

Set objPic = LoadPicture(Source)

With objPic
ScaleValue = .Width / .Height
End With

If MsgBox(ScaleValue, vbOKCancel) = vbCancel Then GoTo LabelA

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

For Each rngZelle In Selection.Cells
With rngZelle
If Not .Comment Is Nothing Then

With .Comment.Shape

.Shadow.Visible = msoFalse

.LockAspectRatio = msoFalse
.Width = 150
' .Width = ScaleValue * .Height
.Height = .Width / ScaleValue
.Fill.UserPicture strFilename
.LockAspectRatio = msoTrue

ScaleValue2 = .Width / .Height

End With
End If
End With
Next rngZelle

LabelA:

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End Sub


2021-07-11 04:30:58

Kurt Müller

Back to the comment standard leads: .Shape.Fill.Solid

With cmt
bVisible = .Visible
.Visible = True
Set rCell = .Parent.Offset(0, 1)
.Shape.CopyPicture _
Appearance:=xlScreen, Format:=xlPicture
rCell.PasteSpecial
Selection.ShapeRange.LockAspectRatio = msoFalse
Selection.Width = rCell.Width
Selection.Height = rCell.Height
.Visible = bVisible

.Shape.Fill.Solid

End With


2015-02-24 04:42:03

Maros(SVK)

Perfect macro, it was helpful for me. Thanks a lot. I deleted the row SHAPE.FILL to keep picture also in the comment.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.