+ Reply to Thread
Results 1 to 6 of 6

retrieving email address from outlook through userform

Hybrid View

  1. #1
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: retrieving email address from outlook through userform

    Here's a function that will retrieve the email address of a user given their name. It uses the Outlook application to create a new mail item, add the user name as the recipient and then resolves the names before retrieving the email address of the user.

    Private outlookApp As Object
    Public Function GetUserEmailAddress(userName As String) As String
    
    Dim mailItem As Object
    Dim recipient As Object
    
    If outlookApp Is Nothing Then Set outlookApp = CreateObject("Outlook.Application")
    
    GetUserEmailAddress = "[Not Found]"
    
    Set mailItem = outlookApp.CreateItem(0)
    mailItem.Recipients.Add userName
    If Not mailItem.Recipients.ResolveAll Then Exit Function
    Set recipient = mailItem.Recipients(1)
    Select Case recipient.AddressEntry.Type
        Case "SMTP"
            GetUserEmailAddress = recipient.AddressEntry.Address
        Case "EX"
            GetUserEmailAddress = recipient.AddressEntry.GetExchangeUser.PrimarySmtpAddress
    End Select
    
    End Function
    WBD

  2. #2
    Registered User
    Join Date
    08-28-2018
    Location
    singapore
    MS-Off Ver
    2016
    Posts
    5

    Re: retrieving email address from outlook through userform

    hi what if my textbox have more than 1 names , and i want to retrieve all the email address?

  3. #3
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: retrieving email address from outlook through userform

    How are you separating the names in the textbox? You could separate them with commas like this:

    Alice Brooks, Charlie Davies, Erica Fletcher, Gordon Haynes

    Then you could use something like this (in conjunction with the previous code):

    Private Sub Searchbutton_Click()
    
    Dim nameList As Variant
    Dim outputList As String
    Dim i As Long
    
    nameList = Split(TextBox1.Text, ",")
    For i = 0 To UBound(nameList)
        outputList = outputList & "," & GetUserEmailAddress(Trim(nameList(i)))
    Next i
    TextBox2.Text = Mid(outputList, 2)
    
    End Sub
    WBD

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Send an email via outlook from and address other than your default email.
    By sungen99 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-28-2015, 06:15 PM
  2. With AutoFilter - copy email address in active cell & paste in To field of Outlook email
    By carmen.swanson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-05-2015, 09:40 PM
  3. Using macro to find email address in address book of Outlook
    By danfullwood in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-22-2014, 06:48 AM
  4. Macro to PDF a sheet in workbook and email (outlook) to an email address in a cell
    By paul_sykes00 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-17-2012, 12:54 AM
  5. Retrieving outlook email count by category
    By jzavala89 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-20-2011, 10:20 AM
  6. sending & retrieving excel data in body of outlook email
    By mismarple in forum Excel General
    Replies: 2
    Last Post: 09-22-2005, 11:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1