<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>www.GuidoDiepen.nl &#187; attachment</title>
	<atom:link href="http://www.guidodiepen.nl/tag/attachment/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.guidodiepen.nl</link>
	<description>Personal Blog of Guido Diepen</description>
	<lastBuildDate>Tue, 29 Mar 2011 16:10:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Preventing the &#8220;Whoops, here you have the attachment&#8221; second email with outlook</title>
		<link>http://www.guidodiepen.nl/2008/11/preventing-the-whoops-here-you-have-the-attachment-second-email-with-outlook/</link>
		<comments>http://www.guidodiepen.nl/2008/11/preventing-the-whoops-here-you-have-the-attachment-second-email-with-outlook/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 21:49:07 +0000</pubDate>
		<dc:creator>guido</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[attachment]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[outlook]]></category>
		<category><![CDATA[vba]]></category>
		<category><![CDATA[warning]]></category>

		<guid isPermaLink="false">http://www.guidodiepen.nl/?p=29</guid>
		<description><![CDATA[<p>Who has never encountered the following problem:</p>
<p>You want to send somebody an email with an attachment. You create the message, hit send and the second you let go of the send button, you think &#8220;%$@!%!^, I forgot to attach the file&#8221;</p>
<p>One of my colleagues had a possible work around for this problem: prevent outlook from [...]]]></description>
			<content:encoded><![CDATA[<p>Who has never encountered the following problem:</p>
<blockquote><p>You want to send somebody an email with an attachment. You create the message, hit send and the second you let go of the send button, you think &#8220;%$@!%!^, I forgot to attach the file&#8221;</p></blockquote>
<p>One of my colleagues had a possible work around for this problem: prevent outlook from sending messages directly when you hit send, but have outlook send all messages in the outbox every given number of minutes. This way, on average you have some time to figure out you forgot to attach something <img src='http://www.guidodiepen.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I have to say that I did not like this work around that much, so I started looking on the internet what I can find as other means to tackle this problem. I found <a title="ablog" href="http://ablog.apress.com/?p=569" target="_blank">aBlog</a> with some VBA macros that will give an additional warning when it appears you forgot an attachment while sending the email.</p>
<p>The author of the original article did have one other complaint, and that was that he was getting a security warning every time the macro was run. This can be solved in two ways: you can either set the security level for macros in Outlook to Low (i.e. every macro can be executed, bad bad idea <img src='http://www.guidodiepen.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ). The other way is to self-sign your VBA project, for which you can also find <a title="Self-signing outlook macros" href="http://www.howto-outlook.com/howto/selfcert.htm" target="_blank">instructions</a> on the internet.</p>
<p>One other thing that I did not like about the code as presented on ablog, is that it does not try to be clever about false positives: If I send an email to somebody with the word attach in it, and that person replies to my email, this reply contains the word attach (because of my original message). If you now reply to this reply again, the macro will detect the word &#8220;attach&#8221; from the original message, and trigger a warning when you try to send the email. I don&#8217;t want to be bothered with warning messages if they are most probably not needed, so the macro almost fit my needs, but not 100% yet <img src='http://www.guidodiepen.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>To overcome this last problem, I have modified the original code just a little bit. Because I hope that somebody else might have some advantage with this modification, I have put it below:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Option</span> <span style="color: #000080;">Explicit</span>
&nbsp;
<span style="color: #000080;">Private</span> <span style="color: #000080;">Sub</span> Application_ItemSend(<span style="color: #000080;">ByVal</span> Item <span style="color: #000080;">As</span> <span style="color: #000080;">Object</span>, Cancel <span style="color: #000080;">As</span> <span style="color: #000080;">Boolean</span>)
  <span style="color: #000080;">If</span> Item.Class = Outlook.olMail <span style="color: #000080;">Then</span>
    <span style="color: #000080;">If</span> Item.Attachments.count = 0 <span style="color: #000080;">Then</span>
      <span style="color: #000080;">If</span> SearchForAttachWords(Item.Body) <span style="color: #000080;">Then</span>
        <span style="color: #000080;">Dim</span> userReply <span style="color: #000080;">As</span> VBA.VbMsgBoxResult
&nbsp;
        userReply = VBA.MsgBox(<span style="color: #800000;">&quot;It appears you are sending the email without attachments while &quot;</span> &amp; _
                           <span style="color: #800000;">&quot;the body/subject contains possible references to an attachment.&quot;</span> &amp; _
                           VBA.vbnewline &amp; <span style="color: #800000;">&quot;Do you want to send the message without attachments?&quot;</span>, _
                           VBA.vbYesNo + VBA.vbDefaultButton2 + VBA.vbQuestion + VBA.vbSystemModal, _
                           <span style="color: #800000;">&quot;Possibly missing attachment...&quot;</span>)
&nbsp;
        <span style="color: #000080;">If</span> userReply = VBA.vbNo <span style="color: #000080;">Then</span>
          Cancel = <span style="color: #000080;">True</span>
        <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
      <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
  <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span>
&nbsp;
<span style="color: #000080;">Function</span> SearchForAttachWords(<span style="color: #000080;">ByVal</span> s <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>) <span style="color: #000080;">As</span> <span style="color: #000080;">Boolean</span>
  <span style="color: #000080;">Dim</span> positionMailTo <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span>
&nbsp;
  positionMailTo = VBA.InStr(1, s, <span style="color: #800000;">&quot;mailto:&quot;</span>, VBA.vbTextCompare)
  <span style="color: #000080;">If</span> positionMailTo = 0 <span style="color: #000080;">Then</span>
    positionMailTo = VBA.InStr(1, s, <span style="color: #800000;">&quot;From:&quot;</span>, VBA.vbTextCompare)
    <span style="color: #000080;">If</span> positionMailTo = 0 <span style="color: #000080;">Then</span>
      positionMailTo = VBA.Len(s)
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
  <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
  <span style="color: #000080;">Dim</span> v <span style="color: #000080;">As</span> <span style="color: #000080;">Variant</span>
&nbsp;
  <span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> v <span style="color: #000080;">In</span> Array(<span style="color: #800000;">&quot;attach&quot;</span>, <span style="color: #800000;">&quot;enclosed&quot;</span>, <span style="color: #800000;">&quot;bijgevoegd&quot;</span>, <span style="color: #800000;">&quot;bijlage&quot;</span>)
    <span style="color: #000080;">Dim</span> tempPos <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span>
    tempPos = VBA.InStr(1, s, v, VBA.vbTextCompare)
&nbsp;
    <span style="color: #008000;">'Only interested in the keywords when they are before mailto:,
</span>    <span style="color: #008000;">'which would be the original message we are replying to
</span>
    <span style="color: #000080;">If</span> (tempPos &lt;&gt; 0) <span style="color: #000080;">And</span> (tempPos &lt; positionMailTo) <span style="color: #000080;">Then</span>
      SearchForAttachWords = <span style="color: #000080;">True</span>
      <span style="color: #000080;">Exit</span> <span style="color: #000080;">Function</span>
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
  <span style="color: #000080;">Next</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></pre></div></div>

<p>To get everything working, copy the above to your clipboard, fire up outlook and press <strong>ALT-F11</strong> to get to the visual basic editor. In the visual basic editor, go to the ThisOutlookSession which can be found under Project1-&gt;Microsoft Outlook Objects. After you copied this and you don&#8217;t want to be annoyed with security warnings of outlook, please follow the earlier mentioned link regarding signing the project with a self-signed certificate.</p>
<p>Some comments regarding the above code:</p>
<ul>
<li>I prefix all functions and values with their respective origin (e.g. VBA.InStr(&#8230;),  VBA.MsgBox(&#8230;), and VBA.vbYesNo, etc ). The reason for this is that at my work, I have outlook 2007 installed on my computer. I have created quite a bunch of macros that are now distributed via copying the VbaProject.otm file. Unfortunately, when other users have outlook 2002 or outlook 2003, they get error messages about things that cannot be found when I do not prefix everything. After the prefixing, there are no problems at all.</li>
<li>bijgevoegd / bijlage are the dutch words for &#8220;attached&#8221; and &#8220;attachment&#8221;. Of course if you want to have the warning trigger on other words, you can put the additional words on this line.</li>
</ul>
<p>Please let me know if you have any additions to the macro that I did not think of yet, or drop me a note in case the macro has saved you from some embarrassing resend  after you just sent a message without attachment <img src='http://www.guidodiepen.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.guidodiepen.nl/2008/11/preventing-the-whoops-here-you-have-the-attachment-second-email-with-outlook/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

