0

I'm currently looking for a way to identity a user of a workbook - preferably by hooking into some account information from Microsoft Excel. I've found the following line which gets the Excel username:

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.

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(??).

Community
  • 1
  • 1
Chri.s
  • 1,386
  • 1
  • 12
  • 23

2 Answers2

0

By "safe" you mean unique? Try

Environ("username")

Application Username is the name of the User set in Excel Tools>Options

Environ("username") is the user name which you log into Windows with.

L0uis
  • 703
  • 5
  • 8
  • It's a good suggestion, however I might not be able to have the users state their Windows username. Do you know whether the returned username is the e-mail, such as in Windows 10 when I (personally) log in with my e-mail? – Chri.s May 18 '18 at 18:45
  • I get my nt login when I call myName = Environ("username") – L0uis May 18 '18 at 19:20
0

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

However, if you are using early-binding in your code, you'll need to add a reference to the 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, i.e. "myname@account.com".


However, for the way my Outlook is setup, I can access my e-mail address as a string via:

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 ?).

Mistella
  • 1,718
  • 2
  • 11
  • 20
  • Won't this technique also require that the user actually has outlook installed and an e-mail account logged in/attached? – Chri.s May 18 '18 at 19:50
  • Yes, it would. I assumed that was the cause, but after rereading your question, I realize it's not.... – Mistella May 18 '18 at 19:52
  • @Chri.s Experimenting around, the following returned my email address, but I haven't had a chance to test in a different situation; and it is entirely possible that this just _happened_ to return the right result. `Environ("Username") & "@" & Replace(LCase(Environ("Userdnsdomain")), "corp.", "")` – Mistella May 18 '18 at 20:39
  • unfortunately it didn't work on my computer and only returned `username@` without the domain. – Chri.s May 18 '18 at 21:42