Looking for a macro that moves completed items from subfolders to other subfolder

Status
Not open for further replies.

sophievldn

New Member
Outlook version
Outlook 365 64 bit
Email Account
Office 365 Exchange
Hello everyone,

I'm new to Outlook VBA and I've been trying to find a macro that would move emails that I mark as complete (that are already inside different subfolders of my inbox) to another subfolder called "DONE". I can't seem to find it online and I'm not great at experimenting with Outlook VBA. Can anyone help me?

Thanks!
Sophie
 
This macro gets close to what you want - instead of sending mail, you will need to move. Are you moving to one folder called done or will there be more than one folder the messages are moved to?

 
Thank you for your reply Diane! There will only be one folder the messages will be moved into.
 
This is a quickie with the basics, but it only works on messages in the inbox.

If you have a lot of folders, it might be better to run a macro at the end of the day (or manually at any time) to move the marked messages.

Code:
Public WithEvents OlItems As Outlook.Items

Public Sub Initialize_handler()
   Set OlItems = Application.GetNamespace("MAPI"). _
        GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub OlItems_ItemChange(ByVal Item As Object)
     
Dim NS As Outlook.NameSpace
Dim fldInbox As Outlook.Folder
Dim fldDone As Outlook.Folder

Set NS = Application.GetNamespace("MAPI")
Set fldInbox = NS.GetDefaultFolder(olFolderInbox)

'subfolder of Inbox
Set fldDone = fldInbox.Folders("Finished")


If Item.Categories = "Done" Then
Item.Move fldDone
End If

End Sub
 
Last edited:
Awesome, thanks Diane! This works!
Is it possible to tweak it so it moves all messages marked as done from the following three folders into the done folder, instead of only from the inbox?
"processing"
"cc mail"
"on hold"
"follow up"

I don't mind if this macro only runs once a day, would you recommend I set that up this way? -> Running Outlook Macros on a Schedule

Thanks for your help Diane, I would definitely not figure this out on my own.
 
You can try this - the big issue is when you have a lot of folders to watch, Outlook might forget. Another macro (will need to write it) can run the MoveDoneMessages on any folder - so if the auto ones fail, you can still move them.

Code:
Private WithEvents OInbox As Outlook.Folder
Private WithEvents fldDone As Outlook.Folder

Public WithEvents OlItems As Outlook.Items
Public WithEvents olProcess As Outlook.Items
Public WithEvents olFollowUp As Outlook.Items
Public WithEvents olCCMail As Outlook.Items
Public WithEvents olOnHold As Outlook.Items


Public Sub Initialize_handler()

Dim NS As Outlook.NameSpace
Set NS = Application.GetNamespace("MAPI")

Set OInbox = NS.GetDefaultFolder(olFolderInbox)

Set OlItems = OInbox.Items
Set fldDone = OInbox.Folders("Finished")

  'subfolders of inbox
  Set olProcess = OInbox.Folders("Processing").Items
  Set olFollowUp = OInbox.Folders("Follow Up").Items
  Set olCCMail = OInbox.Folders("CC Mail").Items
  Set olOnHold = OInbox.Folders("On hold").Items
   
End Sub

Private Sub OlItems_ItemChange(ByVal Item As Object)
  MoveDoneMessages Item
End Sub

Private Sub olProcess_ItemChange(ByVal Item As Object)
  MoveDoneMessages Item
End Sub
   
Private Sub olFollowUp_ItemChange(ByVal Item As Object)
    MoveDoneMessages Item
End Sub

Private Sub olCCMail_ItemChange(ByVal Item As Object)
  MoveDoneMessages Item
End Sub

Private Sub olOnHold_ItemChange(ByVal Item As Object)
  MoveDoneMessages Item
End Sub


Private Sub MoveDoneMessages(ByVal Item As Object)
If Item.Categories = "Done" Then
Item.Move fldDone
End If
End Sub
 
Hi Diane, the issue that Outlook will forget, is that in case I set it up to run once a day? I'm not really following. Could you clarify?

I tried this macro but changed the folder names to match the exact folders in my Outlook + changed the if category is done to if flagstatus is complete because it's the emails that are flagged as complete that should be moved. I'm not sure I did this correctly. I thought so, but it's not working... I put it in ThisOutlookSession and ran it but nothing happened. Could you possibly check if something is wrong?

Thank you so much for your help, I really appreciate it.

Private WithEvents OInbox As Outlook.Folder
Private WithEvents fldDone As Outlook.Folder

Public WithEvents OlItems As Outlook.Items
Public WithEvents olProcess As Outlook.Items
Public WithEvents olFollowUp As Outlook.Items
Public WithEvents olCCMail As Outlook.Items
Public WithEvents olOnHold As Outlook.Items


Public Sub Initialize_handler()

Dim NS As Outlook.NameSpace
Set NS = Application.GetNamespace("MAPI")

Set OInbox = NS.GetDefaultFolder(olFolderInbox)

Set OlItems = OInbox.Items
Set fldDone = OInbox.Folders("08 DONE")

'subfolders of inbox
Set olProcess = OInbox.Folders("02 PROCESSING ST").Items
Set olFollowUp = OInbox.Folders("06 FOLLOW UP").Items
Set olCCMail = OInbox.Folders("03 CC MAIL").Items
Set olOnHold = OInbox.Folders("04 ON HOLD ST").Items

End Sub

Private Sub OlItems_ItemChange(ByVal Item As Object)
MoveDoneMessages Item
End Sub

Private Sub olProcess_ItemChange(ByVal Item As Object)
MoveDoneMessages Item
End Sub

Private Sub olFollowUp_ItemChange(ByVal Item As Object)
MoveDoneMessages Item
End Sub

Private Sub olCCMail_ItemChange(ByVal Item As Object)
MoveDoneMessages Item
End Sub

Private Sub olOnHold_ItemChange(ByVal Item As Object)
MoveDoneMessages Item
End Sub


Private Sub MoveDoneMessages(ByVal Item As Object)
If Item.FlagStatus = olFlagComplete Then
Item.Move fldDone
End If
End Sub
 
Oh, I thought you were assigning a category - not flagging complete.

change the macro to this - if you want to change the name, use find and replace to update it in all of the itemchange macros.
Code:
Private Sub MoveDoneMessages(ByVal Item As Object)

If Item.FlagStatus = olFlagComplete Then
Item.Move fldDone
End If

End Sub
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
B Looking for Outlook 2013 update for Send Drafts Macro Using Outlook 4
Aussie Looking for Outlook macro to Copy Recipient Names into Email Body Outlook VBA and Custom Forms 3
J OL2003 Macro disables itself - looking for way to automate 'enable' Using Outlook 2
C Looking for feedback on new Outlook Add-in Using Outlook 0
B Looking to get the Recipient email address (or even the "friendly name") from an email I am replying to using VBA Outlook VBA and Custom Forms 4
B Looking to filter (or just find/search) for only messages that the sender has sent more than 1 messa Using Outlook 2
G Looking for help with our Organization Forms Library Outlook VBA and Custom Forms 1
peacepanda How to save attachment looking at the attachment name Outlook VBA and Custom Forms 1
D Looking to move away from exchange to outlook.com Using Outlook 4
M Looking for options and best practices for an Edge Server (Exchange or not) Exchange Server Administration 0
M Looking for trainer in Business Contact Manager BCM (Business Contact Manager) 0
O looking to bring in all my folders from Outlook Express (XP) to Outlook 2013 Using Outlook 3
B Looking for an add-in or a way to send automatic replies based off a list Using Outlook 2
R Outlook Template: Looking to distribute a VBA Outlook template to other people Using Outlook 1
J Looking for a solution (maybe an add-in) to easily track email conversations Using Outlook 3
I Looking for a productivity add-in similar to "Nostalgy" for Thunderbird Using Outlook 5
Q Looking for Outlook 2010 Close Event Id Exchange Server Administration 1
C Looking for way to tie a Business Contact to more than one Account BCM (Business Contact Manager) 5
R Looking for my BCM backup files BCM (Business Contact Manager) 1
B Looking for email address under ItemSend event Outlook VBA and Custom Forms 6
S Looking for client-side method (Outlook 2007/Exchange 2007) for users to delete Outlook VBA and Custom Forms 2
S Looking for a Utility for Editting An Exported Rules (.rwz) File Using Outlook 6
P Outlook looking for Copy of Outlook.pst Outlook VBA and Custom Forms 1
U looking for feedback on installation process and on eMarking Assis Outlook VBA and Custom Forms 1
X Custom icon (not from Office 365) for a macro in Outlook Outlook VBA and Custom Forms 1
X Run macro automatically when a mail appears in the sent folder Using Outlook 5
mrrobski68 Issue with Find messages in a conversation macro Outlook VBA and Custom Forms 1
G Creating Macro to scrape emails from calendar invite body Outlook VBA and Custom Forms 6
M Use Macro to change account settings Outlook VBA and Custom Forms 0
J Macro to Reply to Emails w/ Template Outlook VBA and Custom Forms 3
C Outlook - Macro to block senders domain - Macro Fix Outlook VBA and Custom Forms 1
Witzker Outlook 2019 Macro to seach in all contact Folders for marked Email Adress Outlook VBA and Custom Forms 1
S macro error 4605 Outlook VBA and Custom Forms 0
A Macro Mail Alert Using Outlook 4
J Outlook 365 Outlook Macro to Sort emails by column "Received" to view the latest email received Outlook VBA and Custom Forms 0
J Macro to send email as alias Outlook VBA and Custom Forms 0
M Outlook Macro to save as Email with a file name format : Date_Timestamp_Sender initial_Email subject Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Macro GoTo user defined search folder Outlook VBA and Custom Forms 6
D Outlook 2016 Creating an outlook Macro to select and approve Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Macro to send an Email Template from User Defined Contact Form Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Macro to check Cursor & Focus position Outlook VBA and Custom Forms 8
V Macro to mark email with a Category Outlook VBA and Custom Forms 4
M Outlook 2019 Macro not working Outlook VBA and Custom Forms 0
S Outlook 365 Help me create a Macro to make some received emails into tasks? Outlook VBA and Custom Forms 1
D Auto Remove [EXTERNAL] from subject - Issue with Macro Using Outlook 21
V Macro to count flagged messages? Using Outlook 2
S Outlook Macro for [Date][Subject] Using Outlook 1
E Outlook - Macro - send list of Tasks which are not finished Outlook VBA and Custom Forms 3
E Macro to block senders domain Outlook VBA and Custom Forms 1
D VBA Macro to Print and Save email to network location Outlook VBA and Custom Forms 1

Similar threads

Back
Top