OL2000: How to Programmatically Update Company Names

Article translations Article translations
Article ID: 239711 - View products that this article applies to.
This article was previously published under Q239711
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

Summary

This article explains how you can use Outlook Visual Basic for Applications to change the company name for many contacts without having to manually open each contact. This solution is useful if a company changes its name and you have many contacts for that particular company.

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 Microsoft Advisory Services. For more information, visit these Microsoft Web sites:

Microsoft Certified Partners - https://partner.microsoft.com/global/30000104

Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice

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 create the Visual Basic for Applications macro, follow these steps:
  1. On the Tools menu, point to Macro, and then click Macros.
  2. In the Macro Name box, type ChangeCompanyName (without spaces), and then click Create. This starts the Visual Basic Editor and automatically creates a subroutine for you.
  3. Type the following lines of code so that the Visual Basic for Applications procedure appears as follows:
    Sub ChangeCompanyName()
    
       Dim objContactsFolder As Outlook.MAPIFolder
       Dim objContacts As Outlook.Items
       Dim strOldCo As String
       Dim strNewCo As String
       Dim objContact As Object
       Dim iCount As Integer
    
       ' Specify which contact folder to work with
       Set objContactsFolder = Session.GetDefaultFolder(olFolderContacts)
       Set objContacts = objContactsFolder.Items
    
       ' Prompt for old and new company names
       strOldCo = InputBox("Enter the old company name.")
       strNewCo = InputBox("Enter the new company name.")
    
       iCount = 0
    
       ' Process the changes
       For Each objContact In objContacts
          If TypeName(objContact) = "ContactItem" Then
             If objContact.CompanyName = strOldCo Then
                objContact.CompanyName = strNewCo
                objContact.Save
                iCount = iCount + 1
             End If
          End If
       Next
       
       MsgBox "Number of contacts updated:" & Str$(iCount)
    
       ' Clean up
       Set objContact = Nothing
       Set objContacts = Nothing
       Set objContactsFolder = Nothing
    
    End Sub
    					
  4. On the File menu, click Close and Return to Microsoft Outlook.
To use the macro, follow these steps:
  1. On the Tools menu, point to Macro, and then click Macros.
  2. Click the ChangeCompanyName macro, and then click Run.
  3. Wait until a window appears telling you how many contacts have been updated.
Following are some additional notes to be aware of:
  • It may take a while to process the items in the folder. While this happens, the mouse pointer does not change to an hourglass indicating Outlook is running the macro. The Outlook object model does not support changing the mouse pointer in this manner.
  • You can assign the macro to a toolbar button if you use this functionality often. To do this, click View, point to Toolbars, and then click Customize. Change the Categories to Macros, and then drag the macro onto the toolbar. For more information about how to customize toolbars, please see online Help.
  • The code above only works with the default Contacts folder. If you wish to have it work with any contacts folder you have selected, change the following line:
    Set objContactsFolder = Session.GetDefaultFolder(olFolderContacts)
    					
    to:
    Set objContactsFolder = Outlook.ActiveExplorer.CurrentFolder
    					
    If you are familiar with programming and want to use a specific contacts folder in a different location, please see the following article in the Microsoft Knowledge Base for information on how to accomplish that:
    208520 OL2000: Programming Examples for Referencing Items and Folders

References

For additional information about available resources and answers to commonly asked questions about Microsoft Outlook 2000 solutions, please see the following article in the Microsoft Knowledge Base:
146636 OL2000: Questions About Custom Forms and Outlook Solutions
Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See Terms of Use for other considerations.

Properties

Article ID: 239711 - Last Review: October 24, 2013 - Revision: 1.0
Applies to
  • Microsoft Outlook 2000 Standard Edition
Keywords: 
kbnosurvey kbarchive kbhowto kbprogramming KB239711

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com