Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
Preventing the User Name from Appearing in a Comment
To prevent the user name from appearing in a comment, use a Visual Basic
for Applications macro to create the comment. To insert an empty comment in
the active cell, follow these steps:
- Press ALT+F11 to start the Visual Basic Editor. Click Module on the Insert menu, and type the following macro code in a new module:
Sub New_Comment()
ActiveCell.AddComment ("")
ActiveCell.Comment.Visible = True
End Sub
- On the File menu, click Close and Return to Microsoft Excel. Select a cell in a worksheet.
- On the Tools menu, point to Macro, and click Macros. Select the New_Comment macro and click Run.
Microsoft Excel inserts a new comment, without the user name, for the
active cell. - Click in the text area of the comment, and then type the text of the comment.
Inserting a Blank Comment with a Gradient Fill
The following sample macro inserts an empty comment for the active cell.
This comment is formatted with a gradient fill pattern and uses a different
AutoShape and an italic bold font face.
Sub Fancy_Comment()
'Create the comment.
ActiveCell.AddComment ("")
ActiveCell.Comment.Visible = True
ActiveCell.Comment.Shape.Select
With Selection
'Set the AutoShape.
.ShapeRange.AutoShapeType = _
msoShapeExplosion2
'Set background color.
.ShapeRange.Fill.PresetGradient _
msoGradientHorizontal, 1, _
msoGradientHorizon
'Set the font.
.Font.Name = "Arial"
.Font.FontStyle = "Bold Italic"
End With
End Sub
Displaying and Hiding Comments
After you run either of the macros in this article, the comment remains
visible. If you want to hide a single comment, right-click the red triangle in the upper-right corner of the cell and then click
Hide Comment on the shortcut menu. When all comments are hidden, you can display a single comment by resting the pointer over the red triangle. If you want to show or hide all of the comments in the file, click
Comments on the
View menu.