使用VBA的文档的用户名

发布于 2025-01-16 08:52:50 字数 602 浏览 4 评论 0原文

我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ζ澈沫 2025-01-23 08:52:50

“Application”是一个全局对象,你不需要初始化它,“Username”是一个String类型的属性,所以你将有以下代码:

dim sUserName as string

let sUserName = Application.UserName

debug.print sUsername

此外:要给字符串变量赋值,不要使用“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:

dim sUserName as string

let sUserName = Application.UserName

debug.print sUsername

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文