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 December 19, 2024)
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

Documents Printing Out of Order

When printing documents under the control of a macro, you may notice that the documents print out of order for some ...

Discover More

Specifying a Location To Save Automatic Backup Files

When Word creates automatic backups of your documents, you may not like where Word stores them. This naturally leads to ...

Discover More

Creating a Bar Chart for Temperatures

Excel can create a large variety of charts, but sometimes it can take some real creativity to get exactly the chart you ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Linking Comments to Multiple Cells

In Excel, single comments are associated with single cells. If you want to have a comment be linked to multiple cells, ...

Discover More

Static Sizes for Comment Boxes

Adding comments to your worksheet can be helpful in documenting what the worksheet contains. If you want to make sure ...

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
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 2 + 2?

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.