Get current logged in user in Excel office-js add-in
As luck would have it, a one-off (SSO) was released in developer preview the day before you posted your question. As part of the system, your add-in receives a token from the Office host application that contains the "preferred_username" property. The property value is the email address of the user who is registered with Office.
There is an overview of Enable Single Sign-On for Office Add-ins (Preview) .
There are two examples:
In both samples, the add-in also uses the token it received from the Office host to get the Microsoft graphics access token, but your add-in doesn't need to take this extra step.
I don't know how to get the user id without using SSO.
source to share
You can see from the tags that you are talking about javascript addins (office 365). Unfortunately (AFAIK) it is currently not possible to get user information in javascript addons.
Probably your question more or less duplicates this question: How to get username, email, filename from taskbar application
source to share
You don't need to add, it is possible with VBA.
Suppose you want to keep track of which user has changed the value in a cell A1
, you can put this code in a worksheet:
Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
' Do whatever...
Debug.Print Environ("username") & " changed the cell " & Target.Address & " at " & Now()
End If
End Sub
source to share
Single Sign On for Office-js is currently in development, you can start playing with it in preview mode.
source to share