PDA

View Full Version : Bulk email address changes



Davidb
01-17-2008, 11:58 AM
Good morning

Companies often change their names with mergers, take-overs rebranding, etc. Shortly after they change the domain name part of their email address and eventually they will closedown the old domain name. If one corresponds with a large number of people in an organisation that makes such a change it is quite a chore to manually update the old addresses.

Is anyone aware of an Outlook VBA macro that can make changes to the post @ symbol part of the email address in bulk? An interactive routine to locate, view, update/delete would be a great asset.

Regards DavidB :sleuth:

Oorang
01-18-2008, 07:12 AM
I think this ought to do it.

Option Explicit
Private Sub TestAddressBookFindReplace()
AddressBookFindReplace "Contacts", "@baz", "@foo"
End Sub
Public Sub AddressBookFindReplace(addressBookName As String, findText As String, replaceText As String, Optional compareMethod As VbCompareMethod = vbBinaryCompare)
Const lngStart_c As String = "1"
Const lngNotFound As Long = 0
Const lngCount_c As Long = -1
Dim ns As Outlook.NameSpace
Dim al As Outlook.AddressList
Dim ae As Outlook.AddressEntry
Dim strAddr As String
Set ns = Outlook.Session
Set al = ns.AddressLists(addressBookName)
For Each ae In al.AddressEntries
strAddr = vbNullString
strAddr = ae.Address
If InStrB(lngStart_c, strAddr, findText, compareMethod) <> lngNotFound Then
ae.Address = VBA.replace(strAddr, findText, replaceText, lngStart_c, lngCount_c, compareMethod)
ae.Update True, False
End If
Next
End Sub