Pasting Pictures into a Comment

by Allen Wyatt
(last updated April 11, 2020)

3

Andres has a picture in the Clipboard. He would like, for the selected cell, to place the picture into a comment. If the cell has no comment, then one would need to be created. If there is a comment already, then the picture would need to be added to it. Andres knows this would take a macro, but he's not sure how to work with comments in a macro to do what he needs.

Microsoft, in the latest Office 365 version, now refers to comments as notes. For the purposes of this tip, however, I'll continue to refer to them by the traditional comments name.

What Andres wants to do is nowhere near as easy as one might desire. The first problem is that there seems to be no way in VBA to use the Clipboard as the source of an image destined for a comment. It is possible to get around this by changing the source to be an image in a file—in other words, to have the macro allow the user to select an image file that is then placed in the comment.

Sub AddCommentPicture()
    Dim PicChoice As Variant

    If ActiveCell.Comment Is Nothing Then
        ActiveCell.AddComment
    End If
    PicChoice = Application.GetOpenFilename("JPEGs *.jpg,*.jpg")

    If PicChoice = False Then
        MsgBox "No file was selected."
    Else
        ActiveCell.Comment.Shape.Fill.UserPicture PicChoice
        ActiveCell.Comment.Shape.LockAspectRatio = True
    End If
End Sub

The macro tests the active cell to see if it has a comment. If not, it will add one. It then displays an Open dialog box that shows only JPG files. (You can change the GetOpenFilename function's parameter to indicate what types of files should be displayed.) The file you pick is then assigned to the comment.

Note that the code does nothing to resize the image. You can, if desired, add the code necessary to do the resizing. You'll want to add that code directly after the line that locks the aspect ratio of the image, near the end of the macro.

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 (5489) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365.

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

Quicker Multiple Replace Operations

Need to replace a lot of the same characters very, very quickly? Here's a great way to do the replacement.

Discover More

Exporting Latitude and Longitude

A handy way to store latitude and longitude values in Excel is to treat them as regular time values. When it comes around ...

Discover More

Determining How Many Styles are Available

Got a macro that processes or uses styles? You definitely need to know how many styles Word has available in the ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Viewing Comments

There are three different ways that Excel allows you to display any comments that are in your worksheet. Here's how you ...

Discover More

Comments Don't Appear when Cell is Pointed To

One way that you can view comments in a worksheet is to have them appear when you hover the mouse pointer over a cell. If ...

Discover More

Adding a Comment to Multiple Cells

Adding a comment to a single cell is easy. What if you want to add the same comment to multiple cells, however? Here are ...

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}] 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 two more than 9?

2020-04-12 13:40:37

J. Woolley

@Ronmio
For example, to make the height of the comment shape 100 pixels, change the code after Else as follows:

ActiveCell.Comment.Shape.Fill.UserPicture PicChoice
ActiveCell.Comment.Shape.LockAspectRatio = True
ActiveCell.Comment.Shape.Height = 100

When you use VBA to change the comment shape's height, its width will also change because aspect ratio is locked. In this case, the JPG image resizes to match the comment's shape because it was inserted as a background (Fill).

Notice you can manually change the comment shape's height or width independently by dragging a side-handle, but dragging a corner-handle will change both height and width to maintain aspect ratio.


2020-04-11 14:00:28

Ronmio

What might the VBA code that sizes the JPG look like?


2020-04-11 08:15:42

Cliff Raymond

It never occurred to me that an image could be pasted into a comment, or why I would want to, but I still found this fascinating. Thanks!


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.