Setting the Business Address as the Mailing Address in Outlook 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
Overview
Setting the Default Mailing Address
Using Your Custom Post Form
Additional Resources
Overview
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.
Setting the Default Mailing Address
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
Open and design a form for a new post message:
On the File menu of the Inbox folder, point to New, and then click Post in This Folder.
In the new Post form, on the Developer menu, point to Form, and then click Design This Form.
Insert a command button on the form:
Click the (P.2) tab to view a blank page on the form.
On the Tools menu, click Control Toolbox.
In the Control Toolbox, click the CommandButton icon, and then drag it to the blank form page.
Right-click the CommandButton1 control on the form page, and then click Properties.
In the Caption box, type Set Mailing Addresses, and then click OK.
Insert the VBScript code:
On the Form menu, click View Code to open Script Editor.
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
In the Script Editor, on the File menu, click Close to return to the form.
Rename the second page (P.2) tab and publish the custom post form:
On the Design menu, point to Page, and then click Rename Page.
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.
On the Form menu, point to Publish, and then click Publish Form As.
In the Display name box, type the name that you want to use for your new form, such as Set Mailing Addresses.
In the Look In drop-down list, click Personal Forms Library.
Click Publish to publish the form.
If you are prompted to check the Save Form Definition with Item check box, click No.
Close the post message without saving your changes.
Using Your Custom Post Form
The custom post form can now be used to update the contacts contained in a selected folder.
To use the custom post form
Find the folder that contains the contacts that you want to update.
On the File menu, point to New, and then click Choose Form.
In the Look In drop-down list, click Personal Forms Library.
Click your new form in the list, and then click Open.
In the Show menu, click the second page tab, and then click the Set Mailing Addresses button.
Click OK to set the business address as the default mailing address for all contacts in the current folder.
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.
Additional Resources
For more information, see the following resources: