Changing the Reply Address

Add a macro to an Outlook toolbar button to change the current message's reply address.

Sue Mosher

August 25, 2000

4 Min Read
ITPro Today logo in a gray background | ITPro Today


Les Landau, a reader from Australia, wants to use Outlook VBA to change the reply address for an outgoing message. Of course, in the Microsoft Outlook user interface (UI), which Figure 1 shows, he can change the reply address on a message's Options dialog box by typing the new address into the Have replies sent to: field—but that is a lot of clicking and typing. In this installment of Outlook VBA on Demand, I show you how to change the current message's reply address by adding a macro to an Outlook toolbar button. I also provide some useful techniques for getting input from a user and working with recipients.

Listings 1 and 2 present two versions of the necessary core code. Listing 1 provides a user option through which you specify the reply address you want to use, whereas Listing 2 calls a function—Listing 3's GetReplyAddress()—that prompts the user to enter an address (or the name of a Microsoft Exchange Server mailbox) every time. You might run Listing 1's ChangeReplyAddrNoPrompt procedure for the reply address that you use most frequently, and you might use Listing 2's ChangeReplyAddrWithPrompt procedure to specify a less commonly used reply address. Both Listing 1 and Listing 2 pass the current message and the reply address as arguments to AddReplyRecip, which is the procedure you see in Listing 4, page 158. AddReplyRecip updates the message with the new reply address.

The Outlook message property that contains a custom reply address is the ReplyRecipients property. If you press F2 in the Outlook VBA window to look up ReplyRecipients in the Object Browser, which Figure 2, page 158, shows, you might be discouraged that the item appears as "read-only," and you might incorrectly assume that you can't modify the reply address. However, remember that ReplyRecipients is a collection—a group of similar objects. You can't directly modify the ReplyRecipients collection (which is why Object Browser lists it as read-only), but you can use the collection's methods to modify the collection. Virtually every collection in Outlook lets you use the Add method to add a new item. In Listing 4, for example, you add a new recipient to the ReplyRecipients collection by providing the Add method with the name or address as an argument:

Set objReplyRecip = _  colReplyRecips.Add(strName)

To ensure that this reply recipient has a valid address, Listing 4 uses the Resolve method to try to resolve the address for the objReplyRecip Recipient object. (This action is the rough equivalent of clicking Check Names in the UI.) If the address doesn't resolve, the procedure uses the Delete method to delete objReplyRecip and gives you the opportunity to try again.

An important component of many programs is getting information from a user. Listing 3 shows one of the simplest techniques to do so, the InputBox() function, which uses the following syntax:

strText = InputBox(, _
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like