Pasting Pictures into a Comment

Written by Allen Wyatt (last updated April 11, 2020)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


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
    End If
    PicChoice = Application.GetOpenFilename("JPEGs *.jpg,*.jpg")

    If PicChoice = False Then
        MsgBox "No file was selected."
        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.


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 Microsoft 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. ...


Changing Many Link Locations

Word makes it easy to establish links between documents. If you need to change the locations for a lot of links at once, ...

Discover More

Lines that Don't Change When You Type

Create a form in Word and you will invariably be faced with the need to places fill-in-the-blank lines in the document. ...

Discover More

Resizing Your Table

Need to make your table a different size? It's easy to do, using the same general technique you use when resizing a ...

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)

Recognizing Notes and Comments in a Macro

When using macros to process comments, it is best to know the various ways that those comments can be accessed. This tip ...

Discover More

Moving Comment Background Pictures to Cells

When formatting comments, you can use a graphic as a background for the comment box. If you later want to move this ...

Discover More

Pasting Into a Comment

Pasting the contents of a single cell into a comment is rather easy. Pasting the contents of a range of cells is a ...

Discover More

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

View most recent newsletter.


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 nine minus 3?

2021-12-17 18:04:10

J. Woolley

For more discussion, see

2021-12-10 10:03:12

J. Woolley

See for continued discussion.

2021-12-09 12:05:45


Hello Woolley,

I forgot to mention, the file is not blocked.



2021-12-09 12:00:12


Hello Woolley,

Unfortunatelly, I'm not able to see the "new" ribbon after the add-on is installed.
The add-on is also active, but not present somehow. I'm using Office 365.

Any ideas?.


A. López

2021-12-08 10:16:18

J. Woolley

For more on this subject, see

My Excel Toolbox includes the following function that will add a background image to a comment:

2021-12-07 09:09:33


Hello There,

Here is the code that I use, I'm not able to check if there is a picture in the clipboard yet. Maybe someone can help me. BTY, the code is not mine unfortunatelly, credits to the author:

Option Explicit
Sub PictureExport()
Dim TempChart As String, Picture2Export As String
Dim PicWidth As Long, PicHeight As Long
Dim ActSheet As String

ActSheet = ActiveSheet.Name

Selection.Name = "PrintScreen"
Picture2Export = Selection.Name

'Store the picture's height and width in a variable
With Selection
PicHeight = .ShapeRange.Height
PicWidth = .ShapeRange.Width
End With

'Add a temporary chart in sheet1
ActiveChart.Location Where:=xlLocationAsObject, Name:=ActSheet
Selection.Border.LineStyle = 0
TempChart = Selection.Name & " " & Split(ActiveChart.Name, " ")(2)

With ActiveSheet
'Change the dimensions of the chart to suit your need
With .Shapes(TempChart)
.Width = PicWidth
.Height = PicHeight
End With

'Copy the picture

'Paste the picture in the chart
With ActiveChart
End With

'Finally export the chart
.ChartObjects(1).Chart.Export Filename:=ThisWorkbook.Path & "\tmp.jpg", FilterName:="jpg"
End With

ActiveCell.Comment.Shape.Fill.UserPicture ThisWorkbook.Path & "\tmp.jpg"
ActiveCell.Comment.Shape.Width = PicWidth
ActiveCell.Comment.Shape.Height = PicHeight
Kill ThisWorkbook.Path & "\tmp.jpg"
Application.ScreenUpdating = True
End Sub

2021-09-11 07:30:23

Kurt Müller

@ J. Woolley

Or you could put this formula in a worksheet cell:

Does not work fine (comma):


Works fine (semicolon):


2021-09-11 06:38:14

Kurt Müller

@ J. Woolley

Thank you very much.

Works fine:

Sub Image_In_Comment()
ImageInComment "D:/Test/Excel/0-Bilder/Erdbeere-10.jpg", Range("H7")
End Sub

Does not work fine (Compile error: Variable not defined)

Sub Image_In_Comment()
Result = ImageInComment("D:/Test/Excel/0-Bilder/Erdbeere-10.jpg", Range("H7")) '** Compile error: Variable not defined
End Sub

What am I doing wrong?

Works fine in the Immediate Window:

Result = ImageInComment("D:/Test/Excel/0-Bilder/Erdbeere-10.jpg", Range("H7"))

2021-09-06 10:06:55

J. Woolley

@Kurt Müller
As described in my earlier comments, ImageInComment is a Function, not a Sub, so it can be used in a cell formula. If you want to use a Function in VBA instead of a cell formula and ignore the returned result, your example with a Call statement will work. The Application.Evaluate shortcut [H7] is OK, but Range("H7") would be better. Here are two other ways to use the Function in VBA:
ImageInComment "D:/Test/Excel/0-Bilder/Erdbeere-10.jpg", Range("H7")
result = ImageInComment("D:/Test/Excel/0-Bilder/Erdbeere-10.jpg", Range("H7"))
Or you could put this formula in a worksheet cell:

2021-09-05 13:50:48

Kurt Müller

@ J. Woolley

I found the solution now:

Sub ImageInComment()
Call ImageInComment("D:/Test/Excel/0-Bilder/Erdbeere-10.jpg", [H7])
End Sub

I had to enter the above macro in a modul by myself.

2021-09-05 07:08:00

Kurt Müller

@ J. Woolley

I can find Register ImageInComment function (Private Sub ImageInComment_Register()), Image in Target's unthreaded Comment (Public Function ImageInComment(ImageFile, [Target}, [ScaleFactor], [RotateAngle], [NoAuthor])) but I can not find a "Sub ImageInComment".

What am I probably doing wrong?

2021-08-26 18:12:22

J. Woolley

For similar discussion, including the ImageInComment(FilePath,[Target]) function, see:

2021-08-25 11:35:09

Kurt Müller

If a picture is pasted into a comment, the picture takes the size of the comment shape. After that the picture is already distorted.

If distortion of the picture shall be prevented, the following procedure is necessary:

- After choosing the pic it is necessary to calculate the scale of the picture
- With the scale of the picture the size of the comment shape has to be changed to the scale of the picture
- If the picture is pasted into the comment shape - having the same scale as the picture - then the picture is not distorted
- Just now the aspect ratio of the comment shape has to be locked. It is not possible to lock the aspect ratio of the picture pasted into the comment shape

Sub insert_userpicture_in_comments()

'** Dimensionierung der Variablen
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

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

' Dialogfenster zur Auswahl eines Bildes öffnen
strFilename = Application.GetOpenFilename(strFilter)

' Wenn kein Bild ausgewählt wurde, Prozedur beenden
If strFilename = False Then GoTo LabelA

Source = (CStr(strFilename))

' Set objPic = LoadPicture(Bild)
Set objPic = LoadPicture(Source)

With objPic
ScaleValue = .Width / .Height
End With

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

Application.CutCopyMode = False

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

'** Alle markierten rngZellen durchlaufen
For Each rngZelle In Selection.Cells
With rngZelle
If Not .Comment Is Nothing Then
'Insert The Image and Resize
With .Comment.Shape
.LockAspectRatio = msoFalse
.Width = 150
' .Width = ScaleValue * .Height
.Height = .Width / ScaleValue
.Fill.UserPicture strFilename
.LockAspectRatio = msoTrue

ScaleValue2 = .Width / .Height
i = i + 1
Debug.Print i; rngZelle.Address; ScaleValue; ScaleValue2

End With
End If
End With
Next rngZelle

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
On Error GoTo 0
End Sub

2020-04-12 13:40:37

J. Woolley

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


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

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.