Macro keeps e-mail addresses updated

Keeping your Outlook contacts updated can be a real chore, between moves, buyouts, and mergers. This handy macro automates domain name changes in multiple contacts' e-mail addresses.

From telecoms to dot coms to mom-and-pop agencies, businesses are changing their names and associations quicker than you can say “Monday.” Here at TechRepublic, we’ve changed ownership three times since our inception.

The last thing you may want to do with your day is change the e-mail addresses in your Outlook contact files to match the latest name changes that have come down the pike. Still, you have to do it if you don’t want the e-mail you sent to to bounce back because the company’s name has been changed to ABC Industries.

To make it easier to keep up with your clients’ rapidly changing monikers, TechRepublic member Kalyan Dorairaj, an e-business architect with XA TMI in Singapore, has written a macro that updates domain names in your Outlook Contacts folder.

"Say, for example, you had 100 contacts with e-mail addresses such as,… With this macro, you could change all 100 contacts to, etc.,” Dorairaj said.

You’ll find Dorairaj’s macro in Listing A, followed by the steps to set it up to automate this tedious task.

Create the new macro in Outlook
To create the macro, first copy the code in Listing A. Next, click Tools | Macro | Visual Basic Editor, as shown in Figure A. Then, double-click ThisOutlookSession in the left top pane, as shown in Figure B.

Figure A

Figure B

A new editing window will open on the right. Click into the editing pane and paste the copied code. Finally, click File | Close And Return To Microsoft Outlook, as shown in Figure C. You’ll be ready to run the macro.

Figure C

Run the macro
In the following example, Company A has changed its name to Company B and the domain name of every employee’s e-mail address must be changed. The Change Company Name macro makes it an easy task.

To run the macro, click Tools | Macro | Macro. You’ll be presented with the dialog box shown in Figure D. Click on ChangeCompanyName and click Run.

Figure D

Next, you’ll see a warning that the macro will only work on the default Contacts folder unless you’ve clicked on an alternate or subfolder prior to running the macro. If you want to run the macro on a subfolder, close the dialog box, navigate to the folder, and start again.

The dialog box, as shown in Figure E, also asks whether you’d like to be prompted before it makes changes. If you choose Yes, you’ll be asked to verify each change. If you click No, the updates will be made automatically. For the purposes of this article, we’ll click yes.

Figure E

Figure F illustrates the next two dialog boxes you’ll see. The first asks you to type in the original domain name of the company, in this case, Once you’ve done so, click OK. In the next dialog box, type in the new domain, which is in this example. When you click OK, you’ll begin the updating process.

Figure F

Since we chose to be notified of each change, a dialog box will appear asking for confirmation for each change, as shown in Figure G. Click Yes to proceed with the change and, in the subsequent dialog box, click Yes to continue the updating process.

Figure G

Figure H

When the process is complete, the final dialog box will give you the total number of records that were changed, as shown in Figure H. This final box will appear even if you’ve chosen not to be notified of each individual change.

What can you make of it?
With some study of the Outlook Object Model, this macro could be extended to update other fields of your contact as well, according to Dorairaj. Send us your ideas for improving this handy utility, or create your own. If we use your submission in an article, we’ll send you a TechRepublic coffee mug.


Editor's Picks

Free Newsletters, In your Inbox