首页 > 解决方案 > 获取已登录的 Office 365 用户 ID

问题描述

如何在 Excel VBA 中获取已登录的 Office 365 用户 ID?

不是Application.UsernameEnviron("username")

标签: excelvbaoffice365

解决方案


我假设“ID”是指这个人的名字?以下应该工作

Sub getLoggedInUser()

Dim olApp As Object
Dim olNS As Object

Set olApp = CreateObject("Outlook.Application")
Set olNS = olApp.GetNamespace("MAPI")

    With olNS.session.currentuser.AddressEntry.GetExchangeUser
        'some different options for getting the name
        Debug.Print .Name
        Debug.Print .FirstName
        Debug.Print .LastName
        Debug.Print .Alias
    End With

End Sub

推荐阅读