Excel: Add comment author using vba

天涯浪子 提交于 2019-12-02 19:20:35

问题


When I add comments to a cell manually (using the insert comment command) the text is preceded by my username in bold font.

Is it possible to replicate this characteristic for comments created in vba using Range.AddComment() (for whichever user is running the macro) ?


回答1:


You can add the logged in user name (with the user name in bold) like so - this example for cell A1:

Sub EasyTest()
Dim shCmt As Comment
On Error Resume Next
Set shCmt = [a1].Comment
On Error GoTo 0
If shCmt Is Nothing Then
Set shCmt = [a1].AddComment
shCmt.Text Text:=Environ$("UserName") & Chr(10) & "TestMe"
shCmt.Shape.TextFrame.Characters(1, Len(Environ$("UserName"))).Font.Bold = True
Else
MsgBox "cell already has a comment"
End If
End Sub


来源:https://stackoverflow.com/questions/12000052/excel-add-comment-author-using-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!