Microsoft KB Archive/239712

= OL2000: How to Programmatically Change Company Name for Multiple Contacts =

Article ID: 239712

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Outlook 2000 Standard Edition

-



This article was previously published under Q239712



SUMMARY
This article explains how you can programmatically change the Company name for many contact entries without manually editing each contact. This can be useful when a company changes its name.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

https://partner.microsoft.com/global/30000104

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

To Programmatically Change the Company Name
NOTE: Make sure to change "Old Company" and "New Company" in the code, to reflect the old and new company names.  Open a new Contact item. On the Tools menu, point to Forms, and then click Design This Form. On the Form menu, click Control Toolbox. Drag a CommandButton to the General tab of the open form. On the Form menu, click View Code, to open the Script Editor.  In the Script Editor, type the following code: Sub CommandButton1_Click Set objNameSpace = Application.GetNamespace("MAPI") Set objContactsFolder = objNameSpace.GetDefaultFolder(10) Set objContacts = objContactsFolder.Items.Restrict("[MessageClass] _       = 'IPM.Contact'") For Each objContact In objContacts If objContact.CompanyName = "Old Company" Then objContact.CompanyName = "New Company" objContact.Save End If   Next End Sub  On the Script Editor File menu, click Close. On the Form menu, click Run this Form.</li> Click the CommandButton, this is CommandButton1 unless you renamed the button.</li> Open your contacts, and check that the company name is changed to the new name.</li></ol>

<div class="references_section">