Macro to Force Filing of Outlook Inbox

Status
Not open for further replies.
Hi all,

There are so many discussions on this topic, but I don't think anyone has actually resolved this yet. I get lots of emails each day relating to a range of projects I am working on. I am wondering if anyone knows how to write a macro that runs after I have sent an email, which goes through each read email in my intray and then makes me pick a folder into which it should be sent. Ideally it would have a button "ignore" in case I want to keep a particular email in my intray. Sorry if this is a dumb question, but I can't work out how to do it. I have one that works for sent emails, which is great.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
It's "all talk and no action" for a reason - its complicated to loop through the inbox later and the unread search folder reduced the need. If you want it to run only on read mail or mail marked complete, its more complex because there is no action (like the send event) to trigger the macro so you either need to code a timer or run it manually. If you want to move mail as you read it, use the move to command, or in Outlook 2010, assign Quick Steps to F keys for one button moving.




Options include using rules to move messages then use the unread search folder (or a search folder of your liking) to find the mail. (I know several people who never look in their inbox - they use rules to move everything and read in the unread search folder instead.)




Or use one of several tools designed for this scenario. One, Auto-Mate, is a rules replacement that runs later, looking for specific conditions (received x hours ago, marked read, marked complete, flagged, category, from specific people, etc) and moves them accordingly. (I use Auto-Mate to move mail after i'm done with it.) The other tools are search addins like NEO and ClearContext - these classify and index mail so you can easily find by address. (I've trialed both - I recommend them for people who use search folders & categories a lot.)
 
Hi Dianne,

Thanks for your reply - I think you have given me an idea. Is it possible to write a macro that runs itself at certain times (say 10:00am and 3:00pm)? Once it runs, it loops through the inbox looking at each read email then asks for the read email to be either sent to a user chosen folder, or "ignored" (left in the intray for now). I know you're probably super busy so I'm not asking for you to write the code; however, if you think it can be done then maybe I can set about finding a way for the code to be written.
Based on the amount of discussion on this topic, it would probably be a very useful code.

Unfortunately a rules based solution wouldn't work because I could have five emails with the same key words, but each one relates to a different project (hence the need to chose the folder into which the email is filed). Of course the simple solution is to be disciplined and manually file everything every day but a couple of busy days in a row and my "discipline" tends to go out the window!

Thanks again, Greg.
 
Thanks Dianne,

If it's possible then I'll see what I can come up with. If I figure out a way I'll post it here for anyone else.

Regards, Greg
 
Hi Dianne,



I have finished the macro (except automatic initiation) and it is working fine except for one problem - I can't see which email it is filing. To get around this I need some sort of screen.updating = false statement (but that doesn't work in outlook), or to select the email so I can see which one I am filing. Do you happen to know how to do this please?



Regards,



Greg
 
OK, here is the macro. Most of it was written by someone else and I have just messed around a bit to make it do what I wanted. It runs each time Outlook is opened and selects each read email then makes the user pick a folder into which the email should be filed. It probably won't work for other .pst files.

To use it, go to outlook, press AltF11, then double click on project1 (top left hand side), then double click on Microsoft Office Outlook Objects, then double click on This Outlook Session and paste in the code. You may need to make a digital signature or fiddle with security settings to make the macro work (it will probably work when you first copy it in and then not work when you restart Outlook). It only takes a few minutes to do.

' This sub makes the movereademails macro work when Outlook starts up

Private Sub Application_MAPILogonComplete()

Call MovereadEmails

End Sub

' This Macro makes the user file the unread emails in the inbox. If you click cancel it skips to the next email.

Sub MovereadEmails()
' Declare all variables.
Dim objOutlook As Outlook.Application
Dim objNamespace As Outlook.NameSpace
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim objSourceFolder As Outlook.MAPIFolder
Dim objDestFolder As Outlook.MAPIFolder
Dim objVariant As Variant
Dim lngMovedMailItems As Long
Dim intCount As Integer
Dim intDateDiff As Integer
Dim strDestFolder As String

' Create an object for the Outlook application.
Set objOutlook = Application
' Retrieve an object for the MAPI namespace.
Set objNamespace = objOutlook.GetNamespace("MAPI")
' Retrieve a folder object for the source folder.
Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderInbox)

' Loop through the items in the folder. NOTE: This has to
' be done backwards; if you process forwards you have to
' re-run the macro an inverese exponential number of times.
' For now, just run it for 1 email (during testinig)
For intCount = objSourceFolder.Items.Count To 1 Step -1
' Retrieve an object from the folder.
Set objVariant = objSourceFolder.Items.Item(intCount)

'Make it so the email you are about to file becomes visible
If objVariant.UnRead = False And objVariant.Class = olMail Or objVariant.Class = olMeetingRequest Then
objVariant.Display
End If

' Allow the system to process. (Helps you to cancel the
' macro, or continue to use Outlook in the background.)
DoEvents

' Filter objects for emails or meeting requests.
If objVariant.UnRead = False And objVariant.Class = olMail Or objVariant.Class = olMeetingRequest Then
' This is optional, but it helps me to see in the
' debug window where the macro is currently at.
Debug.Print objVariant.SentOn

'This asks the user which folder the email is to be sent to
Set objNS = Application.GetNamespace("MAPI")
Set objDestFolder = objNS.PickFolder
'Now close the email or you end up with all the filed emails open
objVariant.Close olDiscard
'If the user has picked cancel, skip. Otherwise move the email
If Not objDestFolder Is Nothing Then
' Move the object to the destination folder.
objVariant.Move objDestFolder
' advise No. emails moved
lngMovedMailItems = lngMovedMailItems + 1
' Destroy the destination folder object.
Set objDestFolder = Nothing
End If
End If

Next

' Display the number of items that were moved.
MsgBox "Moved " & lngMovedMailItems & " messages(s)."

End Sub
 
A similar macro (written by someone else) I found for forced filing of emails as you send....

' This macro asks you to file your email when you send it

Private Sub Application_ItemSend(ByVal Item As Object, _
Cancel As Boolean)
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Set objNS = Application.GetNamespace("MAPI")
Set objFolder = objNS.PickFolder
If TypeName(objFolder) <> "Nothing" And _
IsInDefaultStore(objFolder) Then
Set Item.SaveSentMessageFolder = objFolder
End If
Set objFolder = Nothing
Set objNS = Nothing

End Sub

' This function supports the send email macro

Public Function IsInDefaultStore(objOL As Object) As Boolean
Dim objApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objInbox As Outlook.MAPIFolder
On Error Resume Next
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Select Case objOL.Class
Case olFolder
If objOL.StoreID = objInbox.StoreID Then
IsInDefaultStore = True
End If
Case olAppointment, olContact, olDistributionList, _
olJournal, olMail, olNote, olPost, olTask
If objOL.Parent.StoreID = objInbox.StoreID Then
IsInDefaultStore = True
End If
Case Else
MsgBox "This function isn't designed to work " & _
"with " & TypeName(objOL) & _
" items and will return False.", _
, "IsInDefaultStore"
End Select
Set objApp = Nothing
Set objNS = Nothing
Set objInbox = Nothing

End Function
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
witzker Macro to move @domain.xx of a Spammail to Blacklist in Outlook 2019 Outlook VBA and Custom Forms 4
S Macro for other actions - Outlook 2007 Outlook VBA and Custom Forms 19
C Macro to extract sender name & subject line of incoming emails to single txt file Outlook VBA and Custom Forms 3
L Macro/VBA to Reply All, with the original attachments Outlook VBA and Custom Forms 2
S Macro to move “Re:” & “FWD:” email recieved the shared inbox to a subfolder in outlook Outlook VBA and Custom Forms 0
S Outlook Macro to send auto acknowledge mail only to new mails received to a specific shared inbox Outlook VBA and Custom Forms 0
S Outlook Macro to move reply mail based on the key word in the subjectline Outlook VBA and Custom Forms 0
Eike Move mails via macro triggered by the click of a button? Outlook VBA and Custom Forms 0
S Macro or plug-in to see if specific person was included in this email Outlook VBA and Custom Forms 3
U Macro for reminders,tasks,calendar Outlook VBA and Custom Forms 4
V macro runs slower on startup than after Outlook VBA and Custom Forms 3
N Macro to move all recipients to CC while replying Outlook VBA and Custom Forms 0
A VBA macro for 15 second loop in send and received just for 1 specific mailbox Outlook VBA and Custom Forms 1
G VBA Macro Calendar Printing Assistant 4
R Help Revising VBA macro to delete email over different time span Outlook VBA and Custom Forms 0
M Outlook macro to automate search and forward process Outlook VBA and Custom Forms 6
R Macro Schedule every day in Outlook Using Outlook 0
L Moving emails with similar subject and find the timings between the emails using outlook VBA macro Outlook VBA and Custom Forms 1
Healy Consultants Macro to remove inside organization distribution list email address when reply to all recepients Outlook VBA and Custom Forms 0
geofferyh Cannot get Macro to SAVE more than one message attachment??? Outlook VBA and Custom Forms 5
N How can I increase/faster outlook VBA Macro Speed ? Using Outlook 2
4 Macro to set the category of Deleted Item? Outlook VBA and Custom Forms 2
D.Moore Folder view settings by VBA macro Outlook VBA and Custom Forms 57
A Outlook macro to create search folder with mail categories as criteria Outlook VBA and Custom Forms 3
Dave A Run macro on existing appointment when it changes Outlook VBA and Custom Forms 1
V Outlook Macro to show Flagged messages Outlook VBA and Custom Forms 2
O Run macro automatically at sending an email Using Outlook 11
R Retain Original Message When Forwarding With Macro Outlook VBA and Custom Forms 3
C Macro to add multiple recipients to message Outlook VBA and Custom Forms 3
B Reply and replyall macro is not working Outlook VBA and Custom Forms 1
O Macro - paste as plain text Outlook VBA and Custom Forms 2
J Help Please!!! Outlook 2016 - VBA Macro for replying with attachment in meeting invite Outlook VBA and Custom Forms 9
witzker Macro to set contact reminder to next day 9:00 Outlook VBA and Custom Forms 45
M Adding Macro to populate "to" "subject" "body" not deleting email string below. Outlook VBA and Custom Forms 5
E Copying data from e-mail attachement to EXCEL file via macro Outlook VBA and Custom Forms 38
M Macro to add date/time stamp to subject Outlook VBA and Custom Forms 4
R VBA macro - new message Outlook VBA and Custom Forms 3
S Example VBA Macro - To Conditionally Change the From Account and Add a BCC Address on Emails Outlook VBA and Custom Forms 11
S Macro using .SendUsingAccount only works the first time, after starting Outlook Outlook VBA and Custom Forms 4
S VBA Macro - Run-time error '424': object required - Help Please Outlook VBA and Custom Forms 3
B VBA Macro for assigning multiple Categories to an email in my Inbox Outlook VBA and Custom Forms 1
N Macro for attachment saved and combine Outlook VBA and Custom Forms 1
Sabastian Samuel HOW DO I FORWARD AN EMAIL WITH MACRO using an email that in the body of another email Outlook VBA and Custom Forms 3
C Search with Google Macro? Outlook VBA and Custom Forms 4
J Outlook 2013 Extract Flag Completed dates to Excel Macro Outlook VBA and Custom Forms 16
M Slow VBA macro in Outlook Outlook VBA and Custom Forms 5
D Print Attachments only in selected emails using a macro Outlook VBA and Custom Forms 3
M Macro for attachments download adjustment Outlook VBA and Custom Forms 3
M VBA macro for Inbox's attachments search Outlook VBA and Custom Forms 0
B Macro to manually move selected emails to network folder Outlook VBA and Custom Forms 1

Similar threads

Top