I tried to find the user name of the word document using VBA and tried to compare it with Author of the specified comment, If they are same notify me else no.
I have written code which is as
Dim oComment as Comment
Set oComment = ActiveDocument.Comments.Item(1)
Dim UserName As Application
Dim Author As Comment
Set UserName = Application.UserName
Set Author = oComment.Contact
Dim UN, AU As Strings
Set UN = CStr(UserName)
Set AU = CStr(Author)
If Not (UN Is AU) Then
If (oComment.Ancestor Is Nothing) Then
MsgBox (ActiveDocument.Comments(LatestCommentIndex).Contact & " has added a new comment")
If I try to run it, it said Type mistach on the line UserName = Application.UserName
Anybody has a workaround it?
"Application" is a global object, you don't need to initialize it, "Username" is a property of type String, so you will have the following code:
Furthermore: to assign a value to a string variable, don't use "Set" but "Let" (which you can ommit at all: UN = sUserName, no casting, no special coomand)