Outlook : Run the VBA macro on send button click

  • Thread starter Thread starter masani paresh
  • Start date Start date
M

masani paresh

Hi Friends,

Is it possible to capture the send button click event from VBA code, read
the body of mail and display message box if there is no attachment attached?

Thanks,
Paresh
 
You could capture the button click, but what about using the SendItem event?

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Tue, 23 Dec 2008 07:21:01 -0800 schrieb masani paresh:
 
Thaks for reply Michael. I did not know SendItem event is available. Could
you point me some example where I can use SendItem event?

How would I get the body of mail being sent? and How could I stop sending
mail if it not meets some requirements?

Thanks,
Paresh
 
In the VBA environment, select Application from the left combobox above the
code window, then select ItemSend from the right combobox. That will create
the declaration of the procedure for you. You can read the body from
Item.Body, and set the Cancel argument to True if you want to cancel the
sending process.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Tue, 23 Dec 2008 19:51:00 -0800 schrieb masani paresh:
 
Thanks for the reply Michael. Could you please tell me how could I make the
form default after adding this macro?

Thanks,
Paresh
 
Paresh, what form do you talk about? The mentioned VBA code cannot be used
as VBScript behind a custom form.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Wed, 24 Dec 2008 03:15:01 -0800 schrieb masani paresh:
 
I found a great macro like you are talking about but I can't remember the
site, but I included the top comment from his macro. Maybe you can do a
search for it.
' VBA program for Outlook, (c) Dan Evans. dan at danevans.co.uk
' Will check if your outgoing email mentions an attachment, but you've
' forgotten to attach it
 
Thanks Carol,

The code mentioned by you is available at
http://ezinearticles.com/?The-Biggest-Hoax---Data-Entry,-Free-Job-Online-Scam&id=259190

It seems to be very useful and thanks for that. It seems to give false
alarm in below situation:

1. I got a mail which has "attach" word and also has attachment
2. Now if I reply to that mail(just to say thanks) without having
"attach" word as I dont want to attach anything then this macro ask for
attachment.

Could you tell me how to get rid of this.

Thanks,
Paresh
 
In situations like that I cancel the macro.

You could write some code to see if the line containing the word 'attach' is
preceeded by a RE: but that would work only if your replies are configured
that way.

Or maybe parse the message looking for ----Original Message--- and stop
searching for the word 'attach'.

Good luck
 
I am not sure but there must be some flag got be set for current oMail item
so that we should know the mail is getting forwarded or replied or just new.

Regards,
PAresh
 
A new email has no EntryID property. It's null string (or in managed code is
String.IsNullOrEmpty()).

You can tell if an item was replied to or forwarded only by looking at the
PR_LAST_VERB_EXECUTED property, not exposed in the Outlook object model.
EXCHIVERB_REPLYTOSENDER (102) is the value if the item was last replied to.
EXCHIVERB_REPLYTOALL (103) is the value if the ReplyAll action was taken,
EXCHIVERB_FORWARD (104) is the value for a message that was forwarded.

To access that property, a PT_LONG (32 bit long) you have to use Outlook
2007's PropertyAccessor with the DASL property tag of
"http://schemas.microsoft.com/mapi/proptag/0x10810003" (not an URL), or you
have to use a different API such as CDO 1.21 (no managed code) or Extended
MAPI (C++ or Delphi only), or a COM wrapper for MAPI such as Redemption
(www.dimastr.com/redemption). For those API's you can use the property tag
0x10810003 (&H10810003 for Basic type languages).

That only applies to the last action taken on the item, and isn't there in
the reply or forward item that's opened as a result of the action.

For those items there is no good way to tell, other than using the Subject
line. That can be altered by the user, and it's language dependent where RE
is used in English but AW is used in German for example.
 
Back
Top