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

Creating a Document Clone

If you need to work with a copy of a document rather than the original document, you can use Word's Open dialog box to ...

Discover More

Using the Status Bar

When developing a macro, you may want to display on the status bar what the macro is doing. Here's how to use this ...

Discover More

Renaming Multiple Files

Got a bunch of files you need renamed? Windows can help you out, but only in a limited manner. This tip shows you how.

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

Managing Comments

If you frequently add comments to cells in a worksheet, Excel provides a variety of tools you can use to manage those ...

Discover More

Searching Comments

Need to find that misplaced comment in your worksheet? It's easy to do using the Find and Replace capabilities of Excel.

Discover More

Copying Comments to Cells

Need to copy whatever is in a comment into a cell on your worksheet? If you have lots of comments, manually doing this ...

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

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.