<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Confessions of a Microsoft Consultant : VBA</title><link>http://blogs.technet.com/doxley/archive/tags/VBA/default.aspx</link><description>Tags: VBA</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Job/Life/Reputation protector 2.0</title><link>http://blogs.technet.com/doxley/archive/2008/11/10/job-life-reputation-protector-2-0.aspx</link><pubDate>Mon, 10 Nov 2008 14:58:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3150390</guid><dc:creator>Daniel Oxley</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.technet.com/doxley/comments/3150390.aspx</comments><wfw:commentRss>http://blogs.technet.com/doxley/commentrss.aspx?PostID=3150390</wfw:commentRss><description>&lt;P&gt;Back in January I &lt;A href="http://blogs.technet.com/doxley/archive/2008/01/23/gulp-did-i-really-just-send-that-to-the-entire-company.aspx" mce_href="http://blogs.technet.com/doxley/archive/2008/01/23/gulp-did-i-really-just-send-that-to-the-entire-company.aspx"&gt;posted&lt;/A&gt; some simple VBA code for adding an “are you sure?” type question to the Reply To All button in Outlook.&amp;nbsp; Since then I have received a few suggestions for improving the code, one of the most common of which was to add to the question box the list of names that the mail will be sent to.&amp;nbsp; So, as requested, you can find below the updated code!&amp;nbsp; &lt;/P&gt;
&lt;P align=center&gt;&lt;A href="http://blogs.technet.com/blogfiles/doxley/WindowsLiveWriter/Jobsaver2_B12E/image_6.png" mce_href="http://blogs.technet.com/blogfiles/doxley/WindowsLiveWriter/Jobsaver2_B12E/image_6.png"&gt;&lt;IMG title=image style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=236 alt=image src="http://blogs.technet.com/blogfiles/doxley/WindowsLiveWriter/Jobsaver2_B12E/image_thumb_2.png" width=484 border=0 mce_src="http://blogs.technet.com/blogfiles/doxley/WindowsLiveWriter/Jobsaver2_B12E/image_thumb_2.png"&gt;&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just place this code in a module in Outlook (you can get to the VBA editor by pressing ALT+F11) and then assign it a button on the toolbar:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR&gt;Sub ReplyToAllGuard()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; On Error GoTo ReplyAllErr&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim myOlApp As Outlook.Application&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim myFolder As Outlook.MAPIFolder&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim myItem As Outlook.MailItem&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim ReplyMail&amp;nbsp; As Outlook.MailItem&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim i As Integer&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set myOlApp = Application&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set myFolder = myOlApp.ActiveExplorer.CurrentFolder&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; iCount = myOlApp.ActiveExplorer.Selection.Count&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; For i = 1 To iCount&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set myItem = myOlApp.ActiveExplorer.Selection.Item(1)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set ReplyMail = myItem.ReplyAll&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Next i&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim mymsg As String&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim strRecipients As String&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim ReplyQ As Integer&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; For Each strRec In ReplyMail.Recipients&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strRecipients = strRecipients &amp;amp; strRec &amp;amp; Chr(13)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Next&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mymsg = "You just clicked Reply to All.&amp;nbsp; Are you sure that this is what you want to do?&amp;nbsp; The following recipients will receive this mail:" &amp;amp; _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Chr(13) &amp;amp; Chr(13) &amp;amp; strRecipients&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ReplyQ = MsgBox(mymsg, vbYesNo, "Job/Life/Reputation protector")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If ReplyQ = vbNo Then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set ReplyMail = Nothing&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Else&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myItem.UnRead = False&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ReplyMail.Display&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;/P&gt;
&lt;P&gt;ReplyAllErr:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If Err.Number = -2147467259 Then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox "The sender has prevented you from being able to reply to all recipients.", vbOKOnly, "Job/Life/Reputation protector"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub&lt;/P&gt;
&lt;P&gt;End Sub&lt;BR&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I also made one another change to the code in order to prevent receiving the error “A program is trying to access e-mail address information stored in Outlook”.&amp;nbsp; This error is generated because Outlook has detected a possible security risk because some ‘unknown’ VBA code is trying to harvest the e-mail addresses from an e-mail; in this case though, we actually want it to!&lt;/P&gt;
&lt;P align=center&gt;&amp;nbsp;&lt;A href="http://blogs.technet.com/blogfiles/doxley/WindowsLiveWriter/Jobsaver2_B12E/image_4.png" mce_href="http://blogs.technet.com/blogfiles/doxley/WindowsLiveWriter/Jobsaver2_B12E/image_4.png"&gt;&lt;IMG title=image style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=184 alt=image src="http://blogs.technet.com/blogfiles/doxley/WindowsLiveWriter/Jobsaver2_B12E/image_thumb_1.png" width=365 border=0 mce_src="http://blogs.technet.com/blogfiles/doxley/WindowsLiveWriter/Jobsaver2_B12E/image_thumb_1.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Basically, instead of initiating a new Outlook session in memory, the code now reuses the existing instance of Outlook, thereby not generating a security problem as the message box is suggesting.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: I amended the code to fix an oversight by me where the code did not clean up after itself!&amp;nbsp; Also, the mail now marks itself as read after&amp;nbsp;you reply&amp;nbsp;- Thanks JP for pointing it out.&lt;/P&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3150390" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/doxley/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://blogs.technet.com/doxley/archive/tags/Office/default.aspx">Office</category><category domain="http://blogs.technet.com/doxley/archive/tags/VBA/default.aspx">VBA</category><category domain="http://blogs.technet.com/doxley/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.technet.com/doxley/archive/tags/Misc/default.aspx">Misc</category><category domain="http://blogs.technet.com/doxley/archive/tags/Tips/default.aspx">Tips</category></item><item><title>Gulp! Did I really just send that to the entire company...?</title><link>http://blogs.technet.com/doxley/archive/2008/01/23/gulp-did-i-really-just-send-that-to-the-entire-company.aspx</link><pubDate>Wed, 23 Jan 2008 13:47:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:2772215</guid><dc:creator>Daniel Oxley</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.technet.com/doxley/comments/2772215.aspx</comments><wfw:commentRss>http://blogs.technet.com/doxley/commentrss.aspx?PostID=2772215</wfw:commentRss><description>&lt;P&gt;I am sure that it has happened to everyone in some way or another.&amp;nbsp; You receive an e-mail from a colleague and decide to reply with some harmless comment/joke/snide remark/insult/opinion* but without realising that you pressed the 'Reply To All' button, nor realising that HR and/or your boss were copied on the e-mail as well.&amp;nbsp; Now you are thinking 'Oh dear' and a way to explain it all away as harmless and inconsequential; sound familiar?&amp;nbsp; Well look no further as you can prevent it from ever happening again with just a few lines of code!&lt;/P&gt;
&lt;P&gt;You can use the following VBA code in a module in Outlook (only tested in Outlook 2007) to request confirmation from you before using the 'Reply To All' button.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Sub ReplyToAllGuard() &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim mymsg As String &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim ReplyQ As Integer &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mymsg = "You just clicked Reply to All.&amp;nbsp; Are you sure that this is what you want to do?" &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ReplyQ = MsgBox(mymsg, vbYesNo, "Job/Life/Reputation protector") &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If ReplyQ = vbNo Then &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Else &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim myOlApp As Outlook.Application &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim myFolder As Outlook.MAPIFolder &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim myItem As Outlook.MailItem &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim ReplyMail&amp;nbsp; As Outlook.MailItem &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim i As Integer &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set myOlApp = CreateObject("Outlook.Application") &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set myFolder = myOlApp.ActiveExplorer.CurrentFolder &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; iCount = myOlApp.ActiveExplorer.Selection.Count &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; For i = 1 To iCount &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set myItem = myOlApp.ActiveExplorer.Selection.item(1) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set ReplyMail = myItem.ReplyAll &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ReplyMail.Display &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Next i &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If &lt;/P&gt;
&lt;P&gt;End Sub&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;Just create a new button on your toolbar (see the snapshot of my toolbar below) and link it to the code that you have added to your module.&amp;nbsp; IIRC, there is also some code somewhere in the help files of Office that does a similar thing, but I could not find it quickly and the above code only took 2 minutes to write.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.technet.com/blogfiles/doxley/WindowsLiveWriter/GulpDidIreallyjustsendthattotheentireco_8D29/image_2.png" mce_href="http://blogs.technet.com/blogfiles/doxley/WindowsLiveWriter/GulpDidIreallyjustsendthattotheentireco_8D29/image_2.png"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=30 alt=image src="http://blogs.technet.com/blogfiles/doxley/WindowsLiveWriter/GulpDidIreallyjustsendthattotheentireco_8D29/image_thumb.png" width=264 border=0 mce_src="http://blogs.technet.com/blogfiles/doxley/WindowsLiveWriter/GulpDidIreallyjustsendthattotheentireco_8D29/image_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;* delete as applicable&lt;/P&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=2772215" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/doxley/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://blogs.technet.com/doxley/archive/tags/Office/default.aspx">Office</category><category domain="http://blogs.technet.com/doxley/archive/tags/VBA/default.aspx">VBA</category></item></channel></rss>