XL2000: Sample Macro to Remove User Name from Comment

ID: Q213766


The information in this article applies to:
  • Microsoft Excel 2000


SUMMARY

By default, the text of a cell comment contains the user name in the first line of the comment. There is no built-in feature that automatically disables inserting the user name in the comment text. However, you can use a Visual Basic for Applications macro to insert a blank comment. This article contains a sample macro that inserts a blank comment in the active cell.

NOTE: The user name that is displayed in the comment is that same name that appears in the User name box when you click Options on the Tools menu, and then click the General tab. If you delete your name from the User name box and click OK, Excel looks at the user name you used when you logged on to your computer and uses that name as the default user name.


MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals 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 needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp

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:
  1. 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:


  2. 
    Sub New_Comment()
    
        ActiveCell.AddComment ("")
        ActiveCell.Comment.Visible = True
    
    End Sub 
  3. On the File menu, click Close and Return to Microsoft Excel. Select a cell in a worksheet.


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


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


REFERENCES

For more information about cell comments, click Microsoft Excel Help on the Help menu, type "About adding comments and highlighting changes in a workbook" in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Additional query words: XL2000 annotation annotate username logon log on in

Keywords : kbprg kbdta kbdtacode xlui KbVBA
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: July 6, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.