We're using Microsoft Office Outlook 2003 with Exchange Server 2003, and we want to be able to send a group of users a message that, when opened, will automatically create on the users' Outlook Bar a folder that's linked to a Web site. How can we script this?
The code sample below shows the simple code needed to add a link to a Web site on the Shortcuts navigation pane (the pane that replaced the Outlook Bar) in Outlook 2003.
Set oGroup = oPane.Contents.Groups("Shortcuts")
Set oShortCut = oGroup.Shortcuts.Add(strURL, displayName)
Here, Application is an Outlook.Application object, strURL is the hyperlink to the Web site, and displayName is the label for the shortcut.
The harder part is incorporating the code into an email message. Outlook doesn't run scripts in the HTML body of an email message, but it does run scripts in published custom forms. Consequently, if you can publish a custom form to the Organizational Forms library (so that all users can access the form definition), you can use a custom form to run the script. Custom message forms are useful for deploying all types of Outlook data and settings—not just shortcuts, but also data such as holidays and calendar color labels. To create a form, follow these steps:
- Click Tools, Options, Mail Format. Clear the Use Microsoft Office Word 2003 to edit email messages check box and turn off any automatic signature.
- Create a new email message. In the body of the message, type the text you want the user to see in the popup notification that Outlook displays when a new message arrives (e.g., "Please open this message and click the button to add a new shortcut to Outlook.").
- Click Tools, Forms, Design This Form to put the current message into form design mode.
- Select the large message body control and drag the top of the control down to make room on the form between the subject and the body of the message.
- The Field Chooser should appear automatically. (If it doesn't, click Form, Field Chooser.) Click New and create two new fields—URL and Display-Name—both with Type and Format set to Text. Drag these fields into the space you left between the subject message and body to complete the design of the page you'll see when you create a new message from this form.
- On the toolbar, click Edit Read Page to switch to the layout the user will see when he or she opens an item that uses this form.
- Drag down the top of the message body control as you did in Step 4.
- Choose Form, Control Toolbox and drag a command button from the Control Toolbox to the blank area you've created. Right-click the command button, choose Properties, and change the caption to "Click to add a shortcut to:".
- From the Field Chooser, drag the URL field to the area to the right of the command button. Delete the URL label. Right-click the text box for the URL field, choose Properties, and click the Read-only check box. This step completes the design of the page that the recipient will see.
- Now you can add code. Choose Form, View Code, and copy the previous code sample into the code window.
- On the form's Properties page, give the form a version number. You'll want to increment the version number whenever you make changes to the form. Choose Tools, Forms, Publish Form, and publish the form to the Organizational Forms library. When you're prompted to select the Save Form Definition with Item check box, click No.
To use the form, use the Tools, Forms, Choose Form command to launch a new message that uses the form. Fill in the Subject, URL, Display-Name, and Recipients fields, then send the message. The user who receives the message needs to open it and click the button, which will run the code in the CommandButton1 _Click event handler shown in Listing 1 and create the shortcut based on the URL and DisplayName that you entered.