使用VBA的文档的用户名
我尝试使用 VBA 查找 Word 文档的用户名,并尝试将其与指定评论的作者进行比较,如果它们相同,请通知我,否则不。
我已经编写了代码,
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")
如果我尝试运行它,它会说类型错误在线 UserName = Application.UserName
有人有解决方法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“Application”是一个全局对象,你不需要初始化它,“Username”是一个String类型的属性,所以你将有以下代码:
此外:要给字符串变量赋值,不要使用“Set”但“Let”(您可以完全省略:UN = sUserName,无转换,无特殊 coomand)
"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)