Export (0) Print
Expand All

Setting the Business Address as the Mailing Address in Outlook 2007

Office 2007

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Summary: Learn how to use a custom post form in Microsoft Office Outlook 2007 to set the business address as the default mailing address for contacts without having to manually open each contact. (3 printed pages)

Microsoft Corporation

April 2009

Applies to: Microsoft Office Outlook 2007

Contents

Microsoft Office Outlook 2007 provides many fields for storing detailed information, such as company name or job title, about each contact. Typically, you have to manually open and update each contact if the value changes for a group of contacts. To regularly edit such information for multiple contacts, it might be helpful to have a custom Outlook form available.

You can use Microsoft Visual Basic Scripting Edition (VBScript) in Outlook 2007 to automatically edit the value of a field for many contacts without manually opening each contact. This article describes how a custom post form can iterate through and set the business address as the default mailing address for all the contacts contained in a folder in Outlook 2007.

The custom post form uses the Outlook 2007 object model to programmatically perform several actions. The custom post form contains a button, that when clicked, verifies that the current folder contains contacts. If the current folder contains contacts, then the code then displays a message that states that the update may take some time. When the message is closed, the code iterates through and sets the business address as the default mailing address for each contact in the current folder. When complete, the code displays a message that states that the update is complete.

To create the custom post form

  1. Open and design a form for a new post message:

    1. On the File menu of the Inbox folder, point to New, and then click Post in This Folder.

    2. In the new Post form, on the Developer menu, point to Form, and then click Design This Form.

  2. Insert a command button on the form:

    1. Click the (P.2) tab to view a blank page on the form.

    2. On the Tools menu, click Control Toolbox.

    3. In the Control Toolbox, click the CommandButton icon, and then drag it to the blank form page.

    4. Right-click the CommandButton1 control on the form page, and then click Properties.

    5. In the Caption box, type Set Mailing Addresses, and then click OK.

  3. Insert the VBScript code:

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

    2. In Script Editor, type the following code.

      Sub CommandButton1_Click()
         CONST olNone = 0
         CONST olHome = 1
         CONST olBusiness = 2
         CONST olOther = 3
         'This only works for contacts in the current folder
         Set CurFolder=Application.ActiveExplorer.CurrentFolder
         If CurFolder.DefaultItemType=2 Then
            MsgBox "This update may take some time. " & _
               "You will be notified when the update is completed." _
               ,,"Contact Tools Message"
            Set MyItems = CurFolder.Items
            For i = 1 to MyItems.Count
               Set MyItem = MyItems.Item(i)
               MyItem.SelectedMailingAddress = olBusiness
               MyItem.Save
            Next
            MsgBox "Done!",64,"Contact Tools Message"
         Else
            MsgBox "The current folder is not a " & _
               "Contact folder." _
               ,64,"Contact Tools Message"
         End If
      End Sub
      
    3. In the Script Editor, on the File menu, click Close to return to the form.

  4. Rename the second page (P.2) tab and publish the custom post form:

    1. On the Design menu, point to Page, and then click Rename Page.

    2. In the Page name box, type the name that you want to use for this page, such as Set Mailing Addresses, and then click OK.

    3. On the Form menu, point to Publish, and then click Publish Form As.

    4. In the Display name box, type the name that you want to use for your new form, such as Set Mailing Addresses.

    5. In the Look In drop-down list, click Personal Forms Library.

    6. Click Publish to publish the form.

    7. If you are prompted to check the Save Form Definition with Item check box, click No.

    8. Close the post message without saving your changes.

The custom post form can now be used to update the contacts contained in a selected folder.

To use the custom post form

  1. Find the folder that contains the contacts that you want to update.

  2. On the File menu, point to New, and then click Choose Form.

  3. In the Look In drop-down list, click Personal Forms Library.

  4. Click your new form in the list, and then click Open.

  5. In the Show menu, click the second page tab, and then click the Set Mailing Addresses button.

  6. Click OK to set the business address as the default mailing address for all contacts in the current folder.

  7. Click OK.

Additional Considerations

It may take some time to process the items in the folder. As 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.

Show:
© 2014 Microsoft