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

Replacing Text and Capitalizing a Letter in One Step

The Find and Replace capabilities of Word are very powerful. You can even use them to do some complex and specific ...

Discover More

Creating an Inline Heading

When settling on an overall design for your document, you need to decide how you want your headings to appear. If you ...

Discover More

Using a Single Password for Multiple Workbooks

While password protecting a workbook does provide some security for the contents in the workbook, if you have several ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Placing Formula Results in a Comment

Excel won't allow you to directly or automatically insert the results of a formula into a cell's comment. You can, ...

Discover More

Changing Comment Color for a Single User

The default color used to format comments is determined by Windows, not Excel. You can adjust the formatting of ...

Discover More

Automatically Placing Text in a Comment

Want to automatically move the contents of a cell into a comment for that cell? It's easy enough to do by using the macro ...

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 five more than 8?

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.