2017-10-10 153 views
0

我從用戶那裏獲得交換在線地址,但我想轉換或以某種方式獲取它們的SMTP地址。VBA - 將Exchange Online電子郵件地址轉換爲SMTP地址

我不知道如何從Email1Address獲取SMTP地址。

Set objOL = CreateObject("Outlook.Application") 
Set objNS = objOL.GetNamespace("MAPI") 
Set objContactsFolder = objNS.GetDefaultFolder(olFolderContacts) 
Set objItems = objContactsFolder.Items 

For Each obj In objItems 
    'Test for contact and not distribution list 
    If obj.Class = olContact Then 
     Set objContact = obj 

     With objContact 

     If .Email1Address <>"" Then 
     'I want to add the SMTP-Address after the .LastNameAndFirstName of a User 
      strFileAs = .LastNameAndFirstName 

     .Email1DisplayName= strFileAs 

     .Save 
     End If 
     End With 
    End If 

    Err.Clear 
Next 
+0

什麼是你已經嘗試過,哪些沒有工作的代碼? – QHarr

+0

搜索'ResolveDisplayNameToSMTP' - 你正在尋找的代碼是Sue Mosher。 –

+0

請參閱[如何將基於Exchange的電子郵件地址轉換爲SMTP電子郵件地址](https://www.add-in-express.com/creating-addins-blog/2009/05/08/outlook-exchange-email-address -smtp /)。 –

回答

0

我用這對電子郵件對象,看看你是否能實現它:

dim email as string 
If myItem.SenderEmailType = "EX" Then 
email = myItem.Sender.GetExchangeUser.PrimarySmtpAddress 
Else 
email = myItem.SenderEmailAdress 
End If 
相關問題