Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


October 2000

Changing the Reply Address


RSS
Subscribe to Windows IT Pro | See More Exchange Server and Outlook Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

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(<prompt>, _
<title>, _
<default>)

InputBox() returns a text string. The only required argument is the prompt. You can omit the title and the default text. Here are a few tips for using InputBox:

  • Build the prompt argument as a separate string variable. Doing so will make your program easier to debug.
  • When you want to put text in quotation marks, use the Quote() function. You'll find the Quote() function in Listing 5.
  • The prompt can include as many as 1000 characters. To make long prompts easier to read, use vbCrLf & vbCrLf to insert a blank line, and divide the prompt into paragraphs. (The vbCrLf constant built into VBA represents a carriage return and line feed.)
  • Test the string that the InputBox() function returns to determine whether the string is empty. The user might have clicked OK in the dialog box that InputBox() presents without typing in anything.

You can also use the MsgBox() function to get user input. Other procedures use MsgBox() simply to display a message to a user. When you use MsgBox() as a function in your code, you can specify the buttons it displays. MsgBox() returns an integer that tells you which button a user clicked. The basic syntax is

intRes = MsgBox(<prompt>, _
<buttons>, _
<title>)

As with InputBox(), the prompt is the only argument that the MsgBox() function requires. For the buttons argument, you can combine built-in Visual Basic (VB) constants. The MsgBox() example that you see in Listing 4 puts the Yes and No buttons on the message box, adds a question mark icon, and sets No as the default.

You now have two more useful Outlook VBA macros to add to your collection. You also know how to use the Add method on a Recipients collection to add a new address and the Delete method on an individual Recipient to remove it from its parent collection. Finally, you've seen how to use the InputBox() and MsgBox() functions to get simple responses from a user.

End of Article



Reader Comments
Great, this solves the overall issue of maintaining a chosen level of discretion when replying to messages directed to alias accounts such jobs@... or info@... Yet, why can't we have a default reply address by mailbox - not by profile? This makes much more sense than having to select an identity each time I create or reply to a message. Really, this should be an 'enhancement' by the Outlook development team... Great solution though - leave it to Sue to come up with the work-around. Good job.

JonR October 05, 2000


Actually, you do have a default reply address for each mailbox, set by the administrator. If you want to see enhancements to the way Outlook handles this, you can send a suggestion to mswish@microsoft.com. They really do read them all!

Sue Mosher March 26, 2001


Tried your code for the "Changing the reply address". No go! The "Set objItem = objApp.ActiveInspector.CurrentItem" produces the Not SET error. I would like to do this but your code leaves me frustrated and searching more.

Mark March 02, 2002


<i>To Mark and other readers,<br><br>

The code won’t work if the user has set Word as the Outlook editor, because WordMail in Outlook 2000 doesn’t expose an Inspector object. However, the code should work fine if you're using the built-in Outlook editor.<br><br>

Cheers,<br><br>

Sue</i>

Sue Mosher March 12, 2002


Thanks Sue - works a treat. This code just makes setting to a constant easier without multiple subs etc. Mind you use only once per message.

Sub ChangeReplyAddrNoPrompt()
Dim objApp As Application
Dim objItem As MailItem
Dim colReplyRecips As Recipients
Dim objReplyRecip As Recipient
Dim strRecipName As String

Set objApp = CreateObject("Outlook.Application")
Set objItem = objApp.ActiveInspector.CurrentItem

' ### USER OPTION - specify reply address ###
strRecipName = "bous@nowhere.man"


If objItem.Class = olMail And _
objItem.Sent = False Then

Set colReplyRecips = objMsg.ReplyRecipients
Set objReplyRecip = colReplyRecips.Add(strRecipName)
objReplyRecip.Resolve

End If

Set objItem = Nothing
Set objApp = Nothing
End Sub

Paul May 02, 2004


Is there a way that I can use a similar process to premanently set the reply to address without user interaction? Or maybe so that they are asked only once when the initially start Outlook?

Gerry May 27, 2004


Is there any way to change the reply to address depending on what mailbox you are replying from. Eg. If I reply to an e-mail in my Inbox then the reply to is me, if I reply to an e-mail in a delegates mailbox, then the reply to is from the delegate.

Dan June 03, 2004


Gerry, the reply address for an account is set in the registry entries for that account or by the Exchange administrator. It's not accessible from Outlook objects.

Sue_Mosher August 19, 2004 (Article Rating: )


Dan, what you might do is have a macros that you use only to reply to items in the other mailbox. That macro would set a different reply address.

Sue_Mosher August 19, 2004 (Article Rating: )


Replying to tricky amazon emails is covered here:

http://www.321books.co.uk/ebooks/outlook-vba-tutorial.htm



mal4mac September 17, 2004 (Article Rating: )


 See More Comments  1   2 

You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

WinInfo Short Takes: Week of November 9, 2009

An often irreverent look at some of the week's other news, including some more Windows 7 sales momentum, some Sophos stupidity, Microsoft's cloud computing self-loathing, more whining from the browser makers, Zoho's "Fake Office," and much, much more ...

Understanding File-Size Limits on NTFS and FAT

A general confusion about files sizes on FAT seems to stem from FAT32's file-size limit of 4GB and partition-size limit of 2TB. ...


Exchange Server and Outlook Whitepapers Take Control of Your Email: Understand the Business Reasons for Email Storage Management

Continuous Data Protection and Recovery for Microsoft Exchange

Related Events WinConnections and Microsoft® Exchange Connections

Check out our list of Free Email Newsletters!

Exchange Server and Outlook eBooks Spam Fighting and Email Security for the 21st Century

Understanding and Leveraging Code Signing Technologies

The Expert's Guide for Exchange 2003: Preparing for, Moving to, and Supporting Exchange Server 2003

Related Exchange Server and Outlook Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format

Exchange & Outlook UPDATE eNewsletter
News, strategies, products, and developments in Exchange Server and Outlook messaging.

Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement