Excel: Add comment author using vba

后端 未结 1 1747
心在旅途
心在旅途 2021-01-29 00:34

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 characterist

1条回答
  •  迷失自我
    2021-01-29 01:06

    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
    

    0 讨论(0)
提交回复
热议问题