-
Outlook Rules Wizard / Custom Action
I made a folder in Outlook "Sent Items" folder, say folder name "ABC".
I want to MOVE any item that is in Sent Items (that is sent to certain people) to that ABC folder.
The problem is that in the rules, I have only "move a copy"... I don't want a copy of it, I want it MOVED !
It's anoying because I have the option to move an email when I receive an item, but not when I send :mad:
So, anyone knows how to do it ?
Also, if it cannot be done, I saw something like "Custom Action" in the wizard, and I found this on the net:
http://msdn.microsoft.com/library/de...pnent_9wxf.asp
But that does not really help me, not enough info, and where IS the sample application ? (CRARUN ?)
-
Re: Outlook Rules Wizard / Custom Action
What version of Outlook are you running? You could just write some VBA code to move sent items to your subfolder.
-
Re: Outlook Rules Wizard / Custom Action
This should do what you need. Allot easier then fighting with the rules wiz.
Place this in Outlooks VBA editor (Alt+F11).
You will need to exit and logoff of Outlook and restart it up again. Make sure macros are enabled.
VB Code:
'ThisOutlookSession
Option Explicit
Public WithEvents SentItemsAdd As Items
Private Sub Application_MAPILogonComplete()
Set SentItemsAdd = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderSentMail).Items
End Sub
Private Sub SentItemsAdd_ItemAdd(ByVal Item As Object)
If Item.Subject = "ABC" Then
Dim oSubFolder As Outlook.MAPIFolder
Set oSubFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderSentMail).Folders("ABC")
Item.Move oSubFolder
Set oSubFolder = Nothing
End If
End Sub
VB/Outlook Guruâ„¢ :D
-
Re: Outlook Rules Wizard / Custom Action
Outlook 2002 (10.2627.3311)
How do you write VBA for Outlook ?
-
Re: Outlook Rules Wizard / Custom Action
Thanks for the code, that works for the Subject, I assume that if I want to move only if I sent to "Smith" then I would do something like:
VB Code:
If Item.To Like "*Smith*" Then
I will send more e-mails tomorow, so I can't test right now... but it looks simple enough, so it should work...
-
Re: Outlook Rules Wizard / Custom Action
Yes, that will work and no Outlook Security prompt since its using the Trusted Application object in VBA.
-
1 Attachment(s)
Re: Outlook Rules Wizard / Custom Action
By the way, by this:
Quote:
Originally Posted by RobDog888
Make sure macros are enabled.
You mean the security setting ?
[edit], nevermind, you already ansered my question
-
Re: Outlook Rules Wizard / Custom Action
:D Just make sure its on medium since its an unsigned vba project.
-
Re: Outlook Rules Wizard / Custom Action
Check out my Tutorial on creating a Digital Signature for a VBA project. This will enable you to sign your
Outlook project and set the security level to High and get rid of the irritating "Enable Macros" message when you
startup Outlook each time. ;)
-
1 Attachment(s)
Re: Outlook Rules Wizard / Custom Action
By the way, is there a way to Always "Enable Macros" ?
-
Re: Outlook Rules Wizard / Custom Action
Do you ALWAYS read my mind ??? :D :D
-
Re: Outlook Rules Wizard / Custom Action
I knew that was coming. See post #9 :D
-
Re: Outlook Rules Wizard / Custom Action
:lol: I guess I'm just having a good day today. :thumb:'s for the Scooby Snack. ;)
-
Re: Outlook Rules Wizard / Custom Action
Thanks, the Digital Signature worked ! :)
Now I have another question (since we are at this :)):
I made a macro in an Excel file wich I sent to someone, and that person has to click on "Enable Marcos" every time.
Now if I add the Digital Signature I just made to that Excel file, when I give the Excel file to that person, does the Digital Signature stay with the file ? I mean, will it apply on that computer also ?
-
Re: Outlook Rules Wizard / Custom Action
No, it will not travel with the Excel file. It is VERY bad to distribute a private digital signature since anyone can use it to write
a virus (signed with your signature) and have you get in trouble. You can get a Public digital signature from a few companies,
like Verisign for ex., but its about $400 a year. Too much for a non-comercial macro. If the other user is going to be able to
view your code then you can send them the link to my Tutorial and they can create their own DS to sign your project with.
This way if they modify it or it ends up doing harm, your off the hook since the DS is generated off of a hardware hash of
their system. ;)
-
Re: Outlook Rules Wizard / Custom Action
I see...
Thanks again for everything... (no more questions :)).... yet.... :)
-
Re: Outlook Rules Wizard / Custom Action
Your Welcome. :)
Its been a while since I have done any Outlook programming (burned out). Its about time I got back into it since MS is going to release
Visual Studio Tools for Office 2005 - Outlook Add-In soon (can't wait. He he :D)
Oh, and late next year we may see Office 12! :D
-
1 Attachment(s)
Re: Outlook Rules Wizard / Custom Action
Hi Rob, now i'm getting this whenever I send something (or every 10 minutes, if I choose "Allow access for 10 minues")
Do you know how to get rid of that window ?
By the way, I'm also making a program that reads e-mails from Outlook, and in that program I'm also getting this window to allow access.
Is there a way to Always allow access for the application I choose (kinda like a firewall) ?
-
Re: Outlook Rules Wizard / Custom Action
Hmm, I thought that that wouldnt happen since the code is in the ThisOutlook session. Did you sign the VBA Project and
is your DS showing as a Trused Cert? It should not have the red circle with an 'x' in it.
Also, in Outlook you need to check always trust all addins and templates.
This is happening because of the .To property being accessed.
-
Re: Outlook Rules Wizard / Custom Action
Quote:
Originally Posted by RobDog888
Hmm, I thought that that wouldnt happen since the code is in the ThisOutlook session. Did you sign the VBA Project and is your DS showing as a Trused Cert? It should not have the red circle with an 'x' in it.
Yea I signed it, no red circle with x.
Quote:
Originally Posted by RobDog888
Also, in Outlook you need to check always trust all addins and templates.
How do I do that ?
-
1 Attachment(s)
Re: Outlook Rules Wizard / Custom Action
Tools > Macro > Security...
-
Re: Outlook Rules Wizard / Custom Action
Thanks for the code snippet, RobDog888...
One question on extending it, however (since I've coded plenty of VBA & VBS, but never for Outlook): Is is easy enough to have it present a "Browse..." box of the possible folders to drop it in?
What I'm looking for is a way to set up my Outlook such that every time I send a message, it immediately prompts me to either (a) delete the "Sent Item" message or (b) move the "Sent Item" to a folder of my choice.
Need to get some Outlook programming references now--the possibilities are endless!
-
Re: Outlook Rules Wizard / Custom Action
Welcome to the Forums.
I'm glad you like my code. :)
Yes, you can get Outlook to popup its MAPIFolder browse dialog box. Do you need it in Outlooks VBA of from VB6/.NET?
-
Re: Outlook Rules Wizard / Custom Action
Here is some VB6 code wich is easily modifiable to VBA for what you asked. ;)
VB Code:
Option Explicit
'Add a reference to MS Outlook xx.0 Object Library
Private Sub Command1_Click()
On Error GoTo MyError
Dim oApp As Outlook.Application
Dim oNS As Outlook.NameSpace
Dim oSource As Outlook.MAPIFolder
Dim oDestination As Outlook.MAPIFolder
Dim oEmail As Object
Dim lRetVal As VbMsgBoxResult
Set oApp = New Outlook.Application
Set oNS = oApp.GetNamespace("MAPI")
Set oSource = oNS.GetDefaultFolder(olFolderSentMail)
Set oDestination = oNS.PickFolder
If Not oDestination Is Nothing Then
If oDestination.DefaultMessageClass <> "IPM.NOTE" And oDestination.DefaultItemType = olMailItem Then
'Do your move stuff here
'Get the latest Sent Item for moving/Deleting
oSource.Items.Sort "[Created]", True
Set oEmail = oSource.Items(1)
lRetVal = MsgBox("Do you want to Move or Delete '" & oEmail.Subject & "'?" & vbNewLine & "Click 'Yes' to Move and 'No' to delete!", vbYesNoCancel, App.ProductName)
If lRetVal = vbYes Then
'Move it
oEmail.Move oDestination
ElseIf lRetVal = vbNo Then
'Find the item in the colection (latest sent item) and delete it
oSource.Items(1).Delete
Else
'Cancel
End If
Else
MsgBox "Invaild 'Destination' folder type!" & vbNewLine & "Folder must be a 'MailItem' type.", vbExclamation + vbOKOnly, App.ProductName
End If
End If
Set oEmail = Nothing
Set oSource = Nothing
Set oDestination = Nothing
Set oNS = Nothing
Set oApp = Nothing
Exit Sub
MyError:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbInformation, App.ProductName
End Sub
-
Re: Outlook Rules Wizard / Custom Action
Yes, inside Outlook is what I was looking for...
The example code looks great--I'll try it tomorrow when I get back to work!
-
Re: Outlook Rules Wizard / Custom Action
RobDog888, you rock--this is great!
So I tried hooking up the above inside the ThisOutlookSession, with the events used in the other code example above, with a few minor changes:
- Had to replace the App.ProductName references with oApp.Name.
- Re-arranged so that the prompt was first, then the move or delete bits.
Here's my almost-working result:
VB Code:
Option Explicit
Public WithEvents SentItemsAdd As Items
Private Sub Application_MAPILogonComplete()
Set SentItemsAdd = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderSentMail).Items
End Sub
Private Sub SentItemsAdd_ItemAdd(ByVal Item As Object)
' On Error GoTo MyError
Dim oApp As Outlook.Application
Dim oNS As Outlook.NameSpace
Dim oSource As Outlook.MAPIFolder
Dim oDestination As Outlook.MAPIFolder
Dim oEmail As Object
Dim lRetVal As VbMsgBoxResult
Set oApp = New Outlook.Application
Set oNS = oApp.GetNamespace("MAPI")
Set oSource = oNS.GetDefaultFolder(olFolderSentMail)
'Get the latest Sent Item for moving/deleting
oSource.Items.Sort "[Created]", True
Set oEmail = oSource.Items(1)
lRetVal = MsgBox("Do you want to Move or Delete '" & oEmail.Subject & "'?" & vbNewLine & "Click 'Yes' to Move and 'No' to delete!", vbYesNoCancel, oApp.Name)
If lRetVal = vbYes Then
'Move it
Set oDestination = oNS.PickFolder
If Not oDestination Is Nothing Then
If oDestination.DefaultMessageClass <> "IPM.NOTE" And oDestination.DefaultItemType = olMailItem Then
oEmail.Move oDestination
End If
Else
MsgBox "Invaild 'Destination' folder type!" & vbNewLine & "Folder must be a 'MailItem' type.", vbExclamation + vbOKOnly, oApp.ProductName
End If
ElseIf lRetVal = vbNo Then
'Delete it
oSource.Items(1).Delete
Else
'Cancel
End If
Set oEmail = Nothing
Set oSource = Nothing
Set oDestination = Nothing
Set oNS = Nothing
Set oApp = Nothing
Exit Sub
MyError:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbInformation, oApp.Name
End Sub
One big bug remains: It picks the wrong email from the Sent Items! Perhaps it's something to do with this line?:
VB Code:
oSource.Items.Sort "[Created]", True
Any ideas?
-
Re: Outlook Rules Wizard / Custom Action
Try changing it to False so it will reverse the sorting direction. Not sure if my dyslexia is an issue here. :)
oSource.Items.Sort "[Created]", False
-
Re: Outlook Rules Wizard / Custom Action
I tried "False" to reverse the sort order, and it came up with the same seemingly random email from the middle of my sent items. I also tried commenting out the Sort method line, and it selects the same random email... methinks the Sort method isn't doing anything.
Instead, I had it go to the last one in the Items collection, and it worked:
VB Code:
Set oEmail = oSource.Items(oSource.Items.Count)
...then I had to fix the line which deletes the email, which also used the Items collection.
The final, working code is this:
VB Code:
Option Explicit
Public WithEvents SentItemsAdd As Items
Private Sub Application_MAPILogonComplete()
Set SentItemsAdd = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderSentMail).Items
End Sub
Private Sub SentItemsAdd_ItemAdd(ByVal Item As Object)
' On Error GoTo MyError
Dim oApp As Outlook.Application
Dim oNS As Outlook.NameSpace
Dim oSource As Outlook.MAPIFolder
Dim oDestination As Outlook.MAPIFolder
Dim oEmail As Object
Dim lRetVal As VbMsgBoxResult
Dim lItemNumber As Long
Set oApp = New Outlook.Application
Set oNS = oApp.GetNamespace("MAPI")
Set oSource = oNS.GetDefaultFolder(olFolderSentMail)
'Get the latest Sent Item for moving/deleting
lItemNumber = oSource.Items.Count
Set oEmail = oSource.Items(lItemNumber)
lRetVal = MsgBox("Do you want to Move or Delete '" & oEmail.Subject & "'?" & vbNewLine & "Click 'Yes' to Move and 'No' to delete!", vbYesNoCancel, oApp.Name)
If lRetVal = vbYes Then
'Move it
Set oDestination = oNS.PickFolder
If Not oDestination Is Nothing Then
If oDestination.DefaultMessageClass <> "IPM.NOTE" And oDestination.DefaultItemType = olMailItem Then
oEmail.Move oDestination
End If
Else
MsgBox "Invaild 'Destination' folder type!" & vbNewLine & "Folder must be a 'MailItem' type.", vbExclamation + vbOKOnly, oApp.ProductName
End If
ElseIf lRetVal = vbNo Then
'Delete it
oSource.Items(lItemNumber).Delete
Else
'Cancel
End If
Set oEmail = Nothing
Set oSource = Nothing
Set oDestination = Nothing
Set oNS = Nothing
Set oApp = Nothing
Exit Sub
MyError:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbInformation, oApp.Name
End Sub
Woo-hoo! Thanks for your help--
-
Re: Outlook Rules Wizard / Custom Action
Glad its working the way you need now. :thumb:
I tried the .Count before I posted earlier but depending on the sorting of the view for my Inbox it would return different items.
Becareful that it doesnt change on you. ;) I am running 2003 btw.
Gangsta Yoda http://www.vbforums.com/attachment.p...chmentid=38679
-
Re: Outlook Rules Wizard / Custom Action
I was playing with another folder event today and realized that this code could be trimmed significantly... so I had to clean it up a bit.
At first I relized that instead of using the .Count property, there's the .GetLast method. (It's amazing what you might find when you actually use the help reference.)
Then I noticed that, when called inside ThisOutlookSession, the event passes a reference to the email item anyway! (In the definition of Private Sub SentItemsAdd_ItemAdd(ByVal Item As Object) ). So there was much cleaning and no worries about getting the wrong email anymore.
Here's my final, final. Really. I mean it this time. :p
VB Code:
Option Explicit
Public WithEvents SentItemsAdd As Items
Private Sub Application_MAPILogonComplete()
Set SentItemsAdd = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderSentMail).Items
End Sub
Private Sub SentItemsAdd_ItemAdd(ByVal Item As Object)
' On Error GoTo MyError
Dim oApp As Outlook.Application
Dim oNS As Outlook.NameSpace
Dim oDestination As Outlook.MAPIFolder
Dim lRetVal As VbMsgBoxResult
Set oApp = New Outlook.Application
Set oNS = oApp.GetNamespace("MAPI")
lRetVal = MsgBox("Do you want to Move or Delete '" & Item.Subject & "'?" & vbNewLine & "Click 'Yes' to Move and 'No' to delete!", vbYesNoCancel, "Sent Items")
If lRetVal = vbYes Then
'Move it
Set oDestination = oNS.PickFolder
If Not oDestination Is Nothing Then
If oDestination.DefaultMessageClass <> "IPM.NOTE" And oDestination.DefaultItemType = olMailItem Then
Item.Move oDestination
End If
Else
MsgBox "Invaild 'Destination' folder type!" & vbNewLine & "Folder must be a 'MailItem' type.", vbExclamation + vbOKOnly, "Sent Items"
End If
ElseIf lRetVal = vbNo Then
'Delete it
Item.Delete
Else
'Cancel
End If
'Cleanup
Set oDestination = Nothing
Set oNS = Nothing
Set oApp = Nothing
Exit Sub
MyError:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbInformation, "SentItemsAdd_ItemAdd"
End Sub
Now to someday make this into an Add-in for portability... :rolleyes:
-
Re: Outlook Rules Wizard / Custom Action
Hi all,
Nice forum; it must be heaven for those understanding VB.
I don't understand it and I'm not a programmer, but I do have a challange and that brought me here. So please be patient with me, I'll try to do my best.
Normally I find my way around with common sense, try & error butthis time I could need some help.
I picked this old posting as it matched closest what I found to my chalange. I'm using outlook 2003!
What I try to achive:
1) manage my in and outgoing email by adding a category to it. I do this by looking for specific codes and words in subject and body.
2) incoming mail I can move using the standard rules in outlook 2003 (tagging them to a category and move them to a specific folder)
3) outgoing mail I would like to keep in specific folders in my local PST file. Using rules like at 2) I can tag the email to a category.
But how can I move them???
I tried some with the code below.
A) My first problem: If I hit ALT+F11 I get a VB editor but how and were to add the code?
All what I see is: Project1 - Microsoft Office Outlook -- This outlook session.
The right screen is grey. I can add a userform or module or class module :sick: Which one??
B) This code is written for Outlook 2000, can I use it for 2003?
C) I tried some things with pasting the code in VB editor but this caused me scary errors in the Outlook client, which is vital for me so I stopped experimenting with it.
Thank for you replies.
Jan-Willem
-
Re: Outlook Rules Wizard / Custom Action
Hi, jwsnl--
The code listed above should work fine in Outlook 2000, 2003 or 2007 (I have tested it on all of these). It is pretty much as simple as pasting everything into the ThisOutlookSession window, then closing and re-opening Outlook.
However (!), taking a closer look, I see that it is using the MAPI profile stuff--so I bet it's expecting to find the Exchange server. I can't remember if I've tried the code on a non-MAPI profile, but it doesn't seem like it would work right.
Are you using local .PST files (POP3 email) only? That might be it... :(
-
Re: Outlook Rules Wizard / Custom Action
Hi Ewall,
Thanks for your replay after such a long time for your previous post.
We do use a exchange server but the policies in our companie ristrict storage on that server to 100MB so we are forced to use local PST files to keep some history on email.
I must admit that my original plan is to move the sent item to a local PST file.
Perhaps you could give me some guidance about how to install the code? It's not unthinkable I did something wrong there.
-
Re: Outlook Rules Wizard / Custom Action
Like I said... I wondering whether it will work at all, even if installed correctly. But here's the installation steps anyway:
- Open Outlook
- Press ALT-F11 to open the Visual Basic window
- Double-click the "ThisOutlookSession" in the left-hand pane to open a (hopefully empty) window
- Paste the code in (you will see that VB automagically puts in dividers etc.--just leave it alone
- Close the VisualBasic windows--save the changes if prompted
- Close all Outlook windows
- Re-open Outlook and give it a test
If it doesn't work and you get errors... Just open up the VB window again and delete all the code you put in; next time you open Outlook the errors will be gone.
-
Re: Outlook Rules Wizard / Custom Action
The original code looks very similar to something I'm trying to do, but have very limited VB experience.
I have an additional exchange mailbox added under my primary exchange mailbox so I can send/receive from this additional shared account. When I send an email from the added/secondary mailbox, it is placed in the "sent items" folder of the primary mailbox. I just want to create a custom rule to move messages sent from the secondary account to the secondary "sent items" folder.
Thoughts?
-
Re: Outlook Rules Wizard / Custom Action
Guys, thanks for posting the code. I have been playing with it to customize it for my needs.
Without being a good VB developer...(I should say I am not developer at all), I have a quick question. I see there is a declaration for ItemSend...What was the reason to use "MAPILogonComplete"?
My question comes from the point that I am trying to capture the item and send it to folder "ABC" even before it is copied to the default "Sent Items" folder. Here is the reason if I manually move an item from foldaer DEF to the Sent Items folder, it automatically triggers the event and I get the question for moving the message.
In other words, is there a way to capture the item even before it is copied to the sent items folder and instead of "scanning" the default Sent Items, just get ItemSend and send the item to the folder....I am just thinking out loud...:D
Thanks a lot!!!
-
Re: Outlook Rules Wizard / Custom Action
I added in a custom vb using the alt-F11 instructions above, but when I open Tools->Rules & Alerts->Change Rule->Edit Rule Settings->perform a custom action.
My new vba sub doesn't appear there. It's empty.
Thanks.
-
Re: Outlook Rules Wizard / Custom Action
Quote:
Originally Posted by
probev
Guys, thanks for posting the code. I have been playing with it to customize it for my needs.
Without being a good VB developer...(I should say I am not developer at all), I have a quick question. I see there is a declaration for ItemSend...What was the reason to use "MAPILogonComplete"?
My question comes from the point that I am trying to capture the item and send it to folder "ABC" even before it is copied to the default "Sent Items" folder. Here is the reason if I manually move an item from foldaer DEF to the Sent Items folder, it automatically triggers the event and I get the question for moving the message.
In other words, is there a way to capture the item even before it is copied to the sent items folder and instead of "scanning" the default Sent Items, just get ItemSend and send the item to the folder....I am just thinking out loud...:D
Thanks a lot!!!
Welcome to the Forums.
MAPILogonComplete is used to initialize the withevents declarations event.
To capture anything before the object is added to the sentitems folder you may try checking out the ItemSend event of the Application Object.
-
Re: Outlook Rules Wizard / Custom Action
Quote:
Originally Posted by
eatinmanna
The original code looks very similar to something I'm trying to do, but have very limited VB experience.
I have an additional exchange mailbox added under my primary exchange mailbox so I can send/receive from this additional shared account. When I send an email from the added/secondary mailbox, it is placed in the "sent items" folder of the primary mailbox. I just want to create a custom rule to move messages sent from the secondary account to the secondary "sent items" folder.
Thoughts?
Also see the ItemSend event. You can copy the item to the sent folder of your secondary sentitems folder and then watch the primary sentitems folder for the default one to show up. When it appears you can delete it since you will already have a copy in your seconday sentitmes folder.
-
Re: Outlook Rules Wizard / Custom Action
Quote:
Originally Posted by
hockey_dave
I added in a custom vb using the alt-F11 instructions above, but when I open Tools->Rules & Alerts->Change Rule->Edit Rule Settings->perform a custom action.
My new vba sub doesn't appear there. It's empty.
Thanks.
"Custom vb"? You should be using hte ThisOutlookSession classhi