Get current logged in user in Excel office-js add-in

I would like to add to my Excel add-in a mechanism to keep track of the last user to take a specific action and the date it was performed. Is it possible to get information about a user who is currently logged into Excel from an add-in?

Thank!

+3


source to share


4 answers


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:

Office-Add-in-ASPNET-SSO



Office-Add-in-Nodejs-SSO

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.

+2


source


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

+1


source


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

      

0


source


Single Sign On for Office-js is currently in development, you can start playing with it in preview mode.

0


source







All Articles