Search code examples
vbamacosms-word

How to set author name in comment in Word using VBA?


I have small Template for MS Word. I want to add comment with hyperlink. I can already add the comment with the following code, but I want to set the author name of that comment. I don't know how to do that.

Here is my working code: (author is not set currently)

URLText = "https:\\www.google.com"
Selection.Comments.Add Range:=Selection.Range
With Selection
        .TypeText (CommentText)                        'Add comment text
        .Hyperlinks.Add Anchor:=Selection.Range, _     'Add hyperlink to comment
        Address:=URLText, _   
        ScreenTip:=URLText, _
        TextToDisplay:=URLText
End With

However I have tried by following code. Which set author name but I can't add hyperlink in my comment by this way:

Dim cmtMyComment As Comment
Dim link As Hyperlink
link.Address = URLText
link.ScreenTip = URLText
link.TextToDisplay = URLText


Set cmtMyComment = Selection.Comments.Add(Range:=Selection.Range, _
Text:=(CommentText)
cmtMyComment.Author = "ABC"

I didn't find property to set hyperlink.

Can anybody suggest me how to set author name? I have tried but didn't find any property.


Solution

  • Well there is an Author property which you can set like so and the hyperlink still works as you can see with the GIF below

    Public Sub AddCommentWithLink()
        URLText = "https:\\www.google.com"
        Set Comment = Selection.Comments.Add(Range:=Selection.Range)
        Comment.Author = "Donald Duck"
        With Selection
                .TypeText (CommentText)
                .Hyperlinks.Add Anchor:=Selection.Range, _
                Address:=URLText, _
                ScreenTip:=URLText, _
                TextToDisplay:=URLText
        End With
    End Sub
    

    Which will result in a comment like this

    enter image description here