Outlook

Find and Replace Address Entries

Ease of Use

Easy

Version tested with

2003 

Submitted by:

Oorang

Description:

Code will search the address book you define, and if it finds value you specify in the email address, it will replace that value with the replacement value you choose. 

Discussion:

"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 organization that makes such a change it is quite a chore to manually update the old addresses." (Thanks to DavidB for a succinct description.) 

Code:

instructions for use

			

Option Explicit Public 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

How to use:

  1. Press Alt F-11 to launch the Visual Basic Editor (VBE).
  2. From the insert menu of the VBE select Module (not Class Module).
  3. Copy/Paste above code paste into module.
  4. Change the find/replace values in TestAddressBookFindReplace as needed.
  5. Name the address book you want searched.
  6. From the Debug menu select Compile Project.
  7. Save File
  8. Press Alt-F8 to run TestAddressBookFindReplace.
 

Test the code:

  1. See "How to Use"
 

Sample File:

No Attachment 

Approved by Jacob Hilderbrand


This entry has been viewed 128 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express