Create a Custom Action

G

Guest

Does anyone know a how to create a Custom Action that I can use in the rules
wizard that will save incomming emails as C:\Emails\<Email Subject>.msg??
 
S

Sue Mosher [MVP-Outlook]

Custom actions are .dll components built with Extended MAPI and C++ or Delphi in such a way that they can be invoked by Rules Wizard. See http://www.slipstick.com/addins/custom.htm for code samples and commercial actions.

If you are using Outlook 2002 or later, you can create a rule with a "run a script" action that invokes not a "script" but a public VBA subroutine with a MailItem or MeetingItem argument, e.g.

A "run a script" rule action actually uses not an external script but a VBA procedure with a MailItem or MeetingItem as its parameter. That item is processed by the code:

Sub RunAScriptRuleRoutine(MyMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim msg As Outlook.MailItem

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set msg = olNS.GetItemFromID(strID)
' do stuff with msg, e.g.
msg.SaveAs "C:\Emails\" & msg.Subject & " " & _
Time & ".msg"

Set msg = Nothing
Set olNS = Nothing
End Sub

See http://www.outlookcode.com/d/code/zaphtml.htm#ol2002 for another example.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
G

Guest

Hi Thanks for the code - it works fine if I take the following code out:

& _
Time

Do you know how I could leave this in?
 
S

Sue Mosher [MVP-Outlook]

That was stupid of me. Most time formats contain characters, such as a colon, that are not allowed in a file name. Use the Format() function to put the time into an allowable format, such as "hhmmss."

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Cillian said:
Hi Thanks for the code - it works fine if I take the following code out:

& _
Time

Do you know how I could leave this in?
 
G

Guest

Hi,

Thanks again - I hope you don't mind if I ask you a further question. When I
copy & paste the email to my desktop it automatically removes any :*&
characters from the file name - is it possible to put this into the script?
 
S

Sue Mosher [MVP-Outlook]

Yes, you can use the Replace() function to replace any character with another or with a blank string ("").

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Cillian said:
Hi,

Thanks again - I hope you don't mind if I ask you a further question. When I
copy & paste the email to my desktop it automatically removes any :*&
characters from the file name - is it possible to put this into the script?
 
K

kblair

Hi Sue

I'm trying to do the same thing but can get no result at all.

I have setup a rule in Outlook 2003 to fire when an email comes in with
"testing" in the subject and to run a script.
I put in the macro code you have above, removing the &_Time. I cant
get it to save anything at all, and receive no errors either.

I just want to save the email as html to a location so that I can then
use other macros to process it. Could you post the complete code for
this again so I could try it please?

Kevin
 
S

Sue Mosher [MVP-Outlook]

Does any VBA code run at all? Make sure you've taken care of the basics listed at http://www.outlookcode.com/d/vbabasics.htm

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
K

kblair

Thanks Sue. I feel like a big pudding : ) Macro security was on.
Your a legend, thanks heaps....

If your every out Kalgoorlie way (West OZ) let me know and I'll buy you
a beer.

Kev
 
G

Guest

Hi Sue,

I've tried the replace function in the form of:

Replace(msg.Subject, ":", "") As String

But I can't get it working in the code - can you help?
 
S

Sue Mosher [MVP-Outlook]

Replace is a function. What is your code doing with the value that it returns?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Cillian said:
Hi Sue,

I've tried the replace function in the form of:

Replace(msg.Subject, ":", "") As String

But I can't get it working in the code - can you help?
 

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