Exel 2007-2010 - auto-insert date when add new or edit comment

2

I see that when I add new a comment to a cell, Excel auto insert my username into it. So I wonder whether or not we can configure the way Excel add header to my comment.
Actually, I need Excel to auto-insert date when I insert a new comment. Can I do it? If yes, can you give some guide to do it!
Thanks! username
add new comment


FYI, I'm trying with some pieces of VBA code, but still can't get anything helpful! Maybe next weekend... humph

Luke

Posted 2011-11-11T08:48:10.503

Reputation: 1 044

1Do you want it for one specific file or Excel in general? – Siim K – 2011-11-11T09:58:54.540

@SiimK I want it for all Excel files. – Luke – 2011-11-14T03:20:47.017

1

you should accept answers from your previous questions. --> see http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work

– JMax – 2011-11-16T09:26:50.423

Answers

2

There isn't any easy way to do this. If it is a one-time thing, you can go into Excel Options and add the date to your user name. You would have to remember to undo the change when done.

Other than that you would have to write some code. Unfortunately, Excel doesn't register an event when you create or edit a comment so you can't edit a comment as it is being created. The best you can do is write a routine to handle the adding of comments. You would then need to always use the macro for adding comments.

Here is a quick example:

Sub AddNewComment()
   Dim sComment As String, rng As Range

   If TypeName(Selection) = "Range" Then
      Set rng = Selection

      sComment = InputBox("Enter your comment.", "Add New Comment")
      If Len(sComment) > 0 Then
         ' append date and username to comment
         sComment = Format(Date, "m/d/yy") & " " & Application.UserName & ":" & vbLf & sComment
         If rng.Comment Is Nothing Then
            rng.AddComment sComment
         Else
            ' append new comment to existing comment
            rng.Comment.Text vbLf & sComment, Len(rng.Comment.Text) + 1, False
         End If

      End If

      Set rng = Nothing
   End If

End Sub

Note: All text will be plain. You can't set part of your text (UserName) as bold with the .Text function.

mischab1

Posted 2011-11-11T08:48:10.503

Reputation: 1 132