Macro handling "Insert comment"

K

KP

Hi,

Can someone help me to write a macro doing the following:

When I click "Insert comment", I want the date and time to be standard in
the comment box just below the first default line with the username.

I want it to be available already when I open the file without having to run
the macro manually or by keyboard selection.

In addition, is it possible - in the same macro - to change the first line
with username from bold to plain text.

Thanks
K. Pedersen
 
K

KP

Hi Ron de Bruin,
I was already aware of the suggested site but I have not found out how to
use the proposal given there.
It seems as if you have to add a toolbar button or shortcut key to run it
and that is not what I want.

I still hope that you or somebody else can help.

Regards
K. Pedersen
 
G

Gord Dibben

You want this on the right-click Insert Comment or on the Worksheet menu
Insert>Comment?

To have it on the Worksheet Menu Insert>Comment just use this revised macro
from Debra.

Tools>Customize.

Select Insert on menu and right-click on Comment and assign macro.

Sub CommentDateTimeAdd()
'adds comment with date and time and username

Dim strDate As String
Dim cmt As Comment

strDate = "dd-mmm-yy hh:mm:ss"
Set cmt = ActiveCell.Comment

If cmt Is Nothing Then
Set cmt = ActiveCell.AddComment
cmt.Text Text:=Application.UserName & Chr(10) _
& Format(Now, strDate) & Chr(10)
Else
cmt.Text Text:=cmt.Text & Chr(10) _
& Format(Now, strDate) & Chr(10)
End If

With cmt.Shape.TextFrame
.Characters.Font.Bold = False
End With

End Sub

To add the macro to the right-click menu...............

Add this to Thisworkbook module

Private Sub Workbook_Open()
With Application.CommandBars("Cell").Controls("Insert Comment")
.OnAction = "Allskeds.xls" & "!CommentDateTimeAdd"
End With
End Sub

If you want to reset the right-click menu..........

Sub reset()
Application.CommandBars("Cell").Controls("Insert Comment").reset
End Sub


Gord Dibben MS Excel MVP
 
J

Jialiang Ge [MSFT]

Hello

From your post, my understanding on this issue is: you wonder how to
customize the initial comment content when users click on "Insert Comment"
button. If I'm off base, please feel free to let me know.

Excel does not expose any event for the action of entering the "Comment"
mode. If it had such an event, we would be able to register it and
customize the "insert comment" action.

As Gord suggested, the workaround is to assign a custom macro to all the
"Insert Comment" buttons, and replace the default insertion action. Apart
from the "Insert Comment" button on the "Insert" menu and worksheet context
menu, I think we also need to assign it to the "Insert Comment" on the
"Reviewing" toolbar:
1. Right click the Excel toolbar and check "Reviewing".
2. Tools->Customize, right click the "Insert Comment" button on the
toolbar, and assign the macro

Hope it helps.

If you have any other concerns or need anything else, please feel free to
let us know.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top