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.
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:
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.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
Excel won't allow you to directly or automatically insert the results of a formula into a cell's comment. You can, ...
Discover MoreExcel makes it easy to filter a data table based on various values in that table. It isn't so easy to filter according to ...
Discover MoreIn Excel, single comments are associated with single cells. If you want to have a comment be linked to multiple cells, ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments