How to launch macro within a rule?

M

mntn-biker

Newbie here and have virtually no vba experience but have a hopefully
simple question. Is it possible to launch a macro within a rule in
Outlook 2003? Here is the macro that I want to launch when I receive an
e-mail from a customer:

Sub txtmsgfw()
Dim msg As Outlook.MailItem
Set msg = Application.CreateItem(olMailItem)
msg.Subject = "Email from Customer"
msg.Display
Set msg = Nothing
End Sub

I am using the rule to create a new simple e-mail message that I can
have forwarded to my cell phone as a text message. I cannot simply use
forwarding since some e-mails from my customers have 8mb attachments and
those don't fly. I don't see anyplace within the rules that can launch
a macro unless I am missing it.

Thanks - Mike
 
M

Michael Bauer [MVP - Outlook]

There's just a simple change necessary as the rule needs to pass the mail
from the customer the the rule:

Sub txtmsgfw(Mail As Outlook.MailItem)
Dim msg As Outlook.MailItem
Set msg = Application.CreateItem(olMailItem)
msg.Subject = "Email from Customer"
msg.Display
Set msg = Nothing
End Sub

--
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 Thu, 14 May 2009 16:43:36 +0100 schrieb mntn-biker:
 
M

mntn-biker

'Michael Bauer [MVP - Outlook said:
;345545']There's just a simple change necessary as the rule needs to
pass the mail
from the customer the the rule:

Sub txtmsgfw(Mail As Outlook.MailItem)
Dim msg As Outlook.MailItem
Set msg = Application.CreateItem(olMailItem)
msg.Subject = "Email from Customer"
msg.Display
Set msg = Nothing
End Sub

--
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 Thu, 14 May 2009 16:43:36 +0100 schrieb mntn-biker:
Newbie here and have virtually no vba experience but have a hopefully
simple question. Is it possible to launch a macro within a rule in
Outlook 2003? Here is the macro that I want to launch when I receive an
e-mail from a customer:

Sub txtmsgfw()
Dim msg As Outlook.MailItem
Set msg = Application.CreateItem(olMailItem)
msg.Subject = "Email from Customer"
msg.Display
Set msg = Nothing
End Sub

I am using the rule to create a new simple e-mail message that I can
have forwarded to my cell phone as a text message. I cannot simply use
forwarding since some e-mails from my customers have 8mb attachments and
those don't fly. I don't see anyplace within the rules that can launch
a macro unless I am missing it.

Thanks - Mike

Maybe I am missing something but shouldn't I be selecting something
from within this window to get my original macro to launch?

[image: http://www.premiertooldesign.com/images/tech/ol2003rule.gif]
 
M

Michael Bauer [MVP - Outlook]

Excactly. If the shown script is in the ThisOutlookSession module, you
should be able to select it.

--
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 Thu, 14 May 2009 18:37:25 +0100 schrieb mntn-biker:
'Michael Bauer [MVP - Outlook said:
;345545']There's just a simple change necessary as the rule needs to
pass the mail
from the customer the the rule:

Sub txtmsgfw(Mail As Outlook.MailItem)
Dim msg As Outlook.MailItem
Set msg = Application.CreateItem(olMailItem)
msg.Subject = "Email from Customer"
msg.Display
Set msg = Nothing
End Sub

--
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 Thu, 14 May 2009 16:43:36 +0100 schrieb mntn-biker:
Newbie here and have virtually no vba experience but have a hopefully
simple question. Is it possible to launch a macro within a rule in
Outlook 2003? Here is the macro that I want to launch when I receive an
e-mail from a customer:

Sub txtmsgfw()
Dim msg As Outlook.MailItem
Set msg = Application.CreateItem(olMailItem)
msg.Subject = "Email from Customer"
msg.Display
Set msg = Nothing
End Sub

I am using the rule to create a new simple e-mail message that I can
have forwarded to my cell phone as a text message. I cannot simply use
forwarding since some e-mails from my customers have 8mb attachments and
those don't fly. I don't see anyplace within the rules that can launch
a macro unless I am missing it.

Thanks - Mike

Maybe I am missing something but shouldn't I be selecting something
from within this window to get my original macro to launch?

[image: http://www.premiertooldesign.com/images/tech/ol2003rule.gif]
 
M

mntn-biker

Michael - Thanks for your help and patience thus far. I have attempted
to paste the code into ThisOutlookSession (please see image below).
When I click on script in the rule window, nothing shows up here. I
have changed the macro security to medium. Do I not have something
correct in the ThisOutlookSession window?

[image: http://www.premiertooldesign.com/images/tech/ol2003rule2.gif]
 
M

Michael Bauer [MVP - Outlook]

Delete the code from modul1, and turn the code in ThisoutlookSession from
Private to Public. Does that help?

--
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 Fri, 15 May 2009 19:05:42 +0100 schrieb mntn-biker:
 
M

mntn-biker

Michael - Thanks! That got me thru that first part. Now I have been
messing with adding a recipient and making it send. Here is my code
(that does not work - see image below):

Public Sub txtmsgfw(Mail As Outlook.MailItem)
Dim msg As Outlook.MailItem
Dim Recip As Outlook.Recipient
Set msg = Application.CreateItem(olMailItem)
msg.Subject = "Email from customer"
Set Recip = .Recipients.Add("(e-mail address removed)")
Recip.Type = olTo
For Each Recip In .Recipients
If Not Recip.Resolve Then
msg.Display
Set msg = Nothing
End If
Next
Send
End Sub

Any ideas?????

Thanks again for your help! I have been able to read thru the code to
understand what it is doing however, I am not sure where to find the
objects at so I have been googling like crazy and finding bits and
pieces for my puzzle.

Error message:

[image: http://www.premiertooldesign.com/images/tech/olrule3.gif]
 
M

Michael Bauer [MVP - Outlook]

this should do it:

Public Sub txtmsgfw(Mail As Outlook.MailItem)
Dim msg As Outlook.MailItem
Dim Recip As Outlook.Recipient
Set msg = Application.CreateItem(olMailItem)
msg.Subject = "Email from customer"
Set Recip = msg.Recipients.Add("(e-mail address removed)")
Recip.Type = olTo
If msg.Recipients.ResolveAll=False Then
msg.Display
Else
msg.Send
End Sub

--
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 Sat, 16 May 2009 20:40:03 +0100 schrieb mntn-biker:
 
M

mntn-biker

Michael - Thanks a million for your help! I did get an error with the
above code and tweaked it a little to get it to work. Here is what I
wound up with:

Public Sub txtmsgfw(Mail As Outlook.MailItem)
Dim msg As Outlook.MailItem
Dim Recip As Outlook.Recipient
Set msg = Application.CreateItem(olMailItem)
msg.Subject = "Email from customer"
Set Recip = msg.Recipients.Add("(e-mail address removed)")
Recip.Type = olTo
msg.Display
msg.Send
End Sub

Now the only thing I need to do to test it is to wait for my texting to
come back online on my phone......

Thanks again - Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top