How to get the email address of the current logged-in user?

后端 未结 3 1219
悲&欢浪女
悲&欢浪女 2020-12-17 21:12

I\'m new to VBA and trying to get an automated word document working. At the moment there is a Button in the document that which upon pressing, will fire off an email with t

3条回答
  •  一整个雨季
    2020-12-17 21:28

    This answer is for Late Binding so you don't need to have reference libraries. Place the following code in a module:

        Dim OL As Object, olAllUsers As Object, oExchUser As Object, oentry As Object, myitem As Object
        Dim User As String
    
        Set OL = CreateObject("outlook.application")
        Set olAllUsers = OL.Session.AddressLists.Item("All Users").AddressEntries
    
        User = OL.Session.CurrentUser.Name
    
        Set oentry = olAllUsers.Item(User)
    
        Set oExchUser = oentry.GetExchangeUser()
    
        msgbox oExchUser.PrimarySmtpAddress
    

提交回复
热议问题