OL2000: How to Programmatically Change Company Name for Multiple Contacts

ID: Q239712


The information in this article applies to:
  • Microsoft Outlook 2000


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 Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp

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.
  1. Open a new Contact item.


  2. On the Tools menu, point to Forms, and then click Design This Form.


  3. On the Form menu, click Control Toolbox. Drag a CommandButton to the General tab of the open form.


  4. On the Form menu, click View Code, to open the Script Editor.


  5. In the Script Editor, type the following code:


  6. 
    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 
  7. On the Script Editor File menu, click Close.


  8. On the Form menu, click Run this Form.


  9. Click the CommandButton, this is CommandButton1 unless you renamed the button.


  10. Open your contacts, and check that the company name is changed to the new name.


Additional query words: OutSol vbscript

Keywords : OffVBS
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: August 31, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.