HeathRobinson
New Member
- Outlook version
- Outlook 365 64 bit
- Email Account
- Office 365 Exchange
Hi - hope this is the right place for this question.
Diane's code block to translate Exchange addresses into email addresses (from here) is great but I've found a wrinkle with our company.
Basically, when someone leaves the company, the IT Department remove them from Exchange.
This seems to cause bother in the address retrieval of the routine, and will fail at the part I've marked bold red below
'### Get the Exchange address
' if not using Exchange, this block can be removed
Dim olEU As Outlook.ExchangeUser
Dim oEDL As Outlook.ExchangeDistributionList
Dim recip As Outlook.Recipient
Set recip = Application.Session.CreateRecipient(strColB)
If InStr(1, strColB, "/") > 0 Then
' if exchange, get smtp address
Select Case recip.AddressEntry.AddressEntryUserType
Case OlAddressEntryUserType.olExchangeUserAddressEntry
Set olEU = recip.AddressEntry.GetExchangeUser
If Not (olEU Is Nothing) Then
strColB = olEU.PrimarySmtpAddress
End If
Case OlAddressEntryUserType.olOutlookContactAddressEntry
Set olEU = recip.AddressEntry.GetExchangeUser
If Not (olEU Is Nothing) Then
strColB = olEU.PrimarySmtpAddress
End If
Case OlAddressEntryUserType.olExchangeDistributionListAddressEntry
Set oEDL = recip.AddressEntry.GetExchangeDistributionList
If Not (oEDL Is Nothing) Then
strColB = olEU.PrimarySmtpAddress
End If
End Select
End If
' ### End Exchange section
My problem is that I'm not brilliant at coding and this is a nest of CASE statements so I can't see how to easily add in an initial argument to check for senders no longer with the company and default to something else (e.g. olItem.SenderName)
Any code whizzes out there who can help?
Diane's code block to translate Exchange addresses into email addresses (from here) is great but I've found a wrinkle with our company.
Basically, when someone leaves the company, the IT Department remove them from Exchange.
This seems to cause bother in the address retrieval of the routine, and will fail at the part I've marked bold red below
'### Get the Exchange address
' if not using Exchange, this block can be removed
Dim olEU As Outlook.ExchangeUser
Dim oEDL As Outlook.ExchangeDistributionList
Dim recip As Outlook.Recipient
Set recip = Application.Session.CreateRecipient(strColB)
If InStr(1, strColB, "/") > 0 Then
' if exchange, get smtp address
Select Case recip.AddressEntry.AddressEntryUserType
Case OlAddressEntryUserType.olExchangeUserAddressEntry
Set olEU = recip.AddressEntry.GetExchangeUser
If Not (olEU Is Nothing) Then
strColB = olEU.PrimarySmtpAddress
End If
Case OlAddressEntryUserType.olOutlookContactAddressEntry
Set olEU = recip.AddressEntry.GetExchangeUser
If Not (olEU Is Nothing) Then
strColB = olEU.PrimarySmtpAddress
End If
Case OlAddressEntryUserType.olExchangeDistributionListAddressEntry
Set oEDL = recip.AddressEntry.GetExchangeDistributionList
If Not (oEDL Is Nothing) Then
strColB = olEU.PrimarySmtpAddress
End If
End Select
End If
' ### End Exchange section
My problem is that I'm not brilliant at coding and this is a nest of CASE statements so I can't see how to easily add in an initial argument to check for senders no longer with the company and default to something else (e.g. olItem.SenderName)
Any code whizzes out there who can help?