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
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 ?)
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™
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
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 ?
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
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 )
Oh, and late next year we may see Office 12!
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
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.
Originally Posted by RobDog888
Also, in Outlook you need to check always trust all addins and templates.
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!
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
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
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
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
Last edited by RobDog888; Aug 15th, 2005 at 11:24 AM.
Reason: Type-o
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
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.
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"
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 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.
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...
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.
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.
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.
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...
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.
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...
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
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
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.