[英]Excel VBA get (unique) ID of excel-user
I'm currently looking for a way to identity a user of a workbook - preferably by hooking into some account information from Microsoft Excel. 我目前正在寻找一种标识工作簿用户的方法-最好是从Microsoft Excel中获取一些帐户信息。 I've found the following line which gets the Excel username:
我发现以下行获得了Excel用户名:
Application.UserName
However this isn't quite "safe" (unique) Enough as I Wish to make sure that only One person/user can use the workbook. 但是,这并不是十分“安全”(独特),我希望确保只有一个人/用户可以使用该工作簿。 It's Easy just Change the username in excel.
只需在excel中更改用户名即可。
Is it possible to get some other account information? 是否可以获取其他帐户信息? I'd prefer the e-mail used with the office/Excel account, however some other answers Say that it probably isn't possible to get that value(??).
我更喜欢Office / Excel帐户使用的电子邮件,但是其他一些答案则说可能无法获得该值(??)。
By "safe" you mean unique? “安全”是指独特吗? Try
尝试
Environ("username")
Application Username is the name of the User set in Excel Tools>Options 应用程序用户名是在Excel工具>选项中设置的用户名
Environ("username") is the user name which you log into Windows with. Environ(“ username”)是用于登录Windows的用户名。
I had spent some time locating how to send an e-mail to the sending account (for self-notifications), and found an answer, and experimented, and explored some more, until I found that the following worked for my purposes: 我花了一些时间查找如何将电子邮件发送到发送帐户(用于自我通知),找到了答案,进行了尝试,并进行了更多探索,直到发现以下内容对我有用:
Outlook.Application.Session.CurrentUser.Address
This answer recommends Application.Session.CurrentUser.AddressEntry.Address
此答案推荐
Application.Session.CurrentUser.AddressEntry.Address
However, if you are using early-binding in your code, you'll need to add a reference to the Microsoft Outlook [version#] Object Library
. 但是,如果在代码中使用早期绑定,则需要添加对
Microsoft Outlook [version#] Object Library
的引用。
Also , note that the above does not return a value which can be compared with either a hard-coded or an in-put value in standard email format, ie "myname@account.com". 另外 ,请注意,上述内容不会返回可以与标准电子邮件格式的硬编码值或输入值进行比较的值,即“ myname@account.com”。
However , for the way my Outlook is setup, I can access my e-mail address as a string via: 但是 ,对于设置Outlook的方式,我可以通过以下方式以字符串形式访问电子邮件地址:
outlookApp.Session.Accounts(1).DisplayName
I will caution, however, that I have also read of times when this gave an unexpected value. 但是,我会提醒我,我也读过很多次这给人以意外的价值。 It is also based of the first account listed;
它也基于列出的第一个帐户; which may not always be the account for the
CurrentUser
, depending (on ?). (取决于(取决于)),这可能并不总是
CurrentUser
的帐户。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.