I tinkered together a VBA macro. Open your VBA editor with ALT+F11 and paste the below code under sheet1. Execute the macro with ALT+F8
What the macro does
- Ask user for a path to a picture which he wants to insert (can be jpg, bmp or png)
Load that picture as a
WIA.imageFile
. Later we useobjImage.Height
andobjImage.Width
to get the real picture dimensions.This method was the shortest one I've found to get dimensions in pixels (other VBA methods may give you twips. They are a horrible invention)
- Insert a blank comment on the currently selected cell if no old comment already exists there
- Set the chosen picture as background image for the comment shape
- Resize the comment shape dimensions so the picture perfectly fits
Sub InsertComment() Dim strImagePath As Variant Dim objImage As Object strImagePath = Application.GetOpenFilename("Picture, *.jpg; *.png; *.bmp") If strImagePath = False Then Exit Sub Set objImage = CreateObject("WIA.ImageFile") objImage.LoadFile strImagePath With ActiveCell If .Comment Is Nothing Then .AddComment ("") .Comment.Shape.Fill.UserPicture strImagePath .Comment.Shape.Height = objImage.Height * 0.75 .Comment.Shape.Width = objImage.Width * 0.75 End With End Sub