Outlook 7 VBA macro for multiple filing

Status
Not open for further replies.

SiSept

New Member
Outlook version
Outlook 2007
Email Account
Exchange Server
I can't get this to work. Should move emails to multiple folders based on categories and delete inbox original. It did work and then it didn't. Seems to be a Next or For or If issue!

Sub Test()

Dim ns As Outlook.NameSpace
Dim objItem As Object
Dim FolderInbox As Folder
Dim MyItem As Outlook.MailItem

'// Added - A collection to hold the IDs of message to be deleted
Dim cMAILS As Collection

Set ns = Application.GetNamespace("MAPI")
Set FolderInbox = ns.GetDefaultFolder(olFolderInbox)
Set cMAILS = New Collection

For Each objItem In FolderInbox.Items

'// You need one block for each category...
If InStr(objItem.Categories, "SMT AGENDA") > 0 Then
Set MyItem = objItem.Copy
MyItem.Move FolderInbox.Folders("AGENDAS 01 SMT")

If InStr(objItem.Categories, "SMT TEAM LEADERS") > 0 Then
Set MyItem = objItem.Copy
MyItem.Move FolderInbox.Folders("AGENDAS 02 TEAM LEADERS MEETING")

If InStr(objItem.Categories, "COMMUNICATION") > 0 Then
Set MyItem = objItem.Copy
MyItem.Move FolderInbox.Folders("AGENDAS 03 COMMUNICATION MEETING")

If InStr(objItem.Categories, "CAROL MAITLAND") > 0 Then
Set MyItem = objItem.Copy
MyItem.Move FolderInbox.Folders("AGENDAS 04 CAROL MAITLAND")

If InStr(objItem.Categories, "MANAGEMENT") > 0 Then
Set MyItem = objItem.Copy
MyItem.Move FolderInbox.Folders("AGENDAS 05 MANAGEMENT")

If InStr(objItem.Categories, "ADP SUPPORT TEAM") > 0 Then
Set MyItem = objItem.Copy
MyItem.Move FolderInbox.Folders("PROJECTS 01 ADP")

If InStr(objItem.Categories, "BBV") > 0 Then
Set MyItem = objItem.Copy
MyItem.Move FolderInbox.Folders("PROJECTS 02 BBV")

If InStr(objItem.Categories, "CHILDRENS SERVICES") > 0 Then
Set MyItem = objItem.Copy
MyItem.Move FolderInbox.Folders("PROJECTS 03 CPC CHILDRENS SERVICES")

If InStr(objItem.Categories, "D&I") > 0 Then
Set MyItem = objItem.Copy
MyItem.Move FolderInbox.Folders("PROJECTS 04 D&I")

If InStr(objItem.Categories, "EARLIER INTERVENTION") > 0 Then
Set MyItem = objItem.Copy
MyItem.Move FolderInbox.Folders("PROJECTS 05 DIRECT ACCESS")

If InStr(objItem.Categories, "FINANCE") > 0 Then
Set MyItem = objItem.Copy
MyItem.Move FolderInbox.Folders("PROJECTS 06 FINANCE")

If InStr(objItem.Categories, "IAS") > 0 Then
Set MyItem = objItem.Copy
MyItem.Move FolderInbox.Folders("PROJECTS 07 IAS REDESIGN")

If InStr(objItem.Categories, "KEEPWELL") > 0 Then
Set MyItem = objItem.Copy
MyItem.Move FolderInbox.Folders("PROJECTS 08 KEEPWELL")

If InStr(objItem.Categories, "KEY PRIORITY") > 0 Then
Set MyItem = objItem.Copy
MyItem.Move FolderInbox.Folders("PROJECTS 09 KEY AIM AND NALOXONE")

If InStr(objItem.Categories, "MARYWELL") > 0 Then
Set MyItem = objItem.Copy
MyItem.Move FolderInbox.Folders("PROJECTS 10 MARYWELL")

If InStr(objItem.Categories, "PFR") > 0 Then
Set MyItem = objItem.Copy
MyItem.Move FolderInbox.Folders("PROJECTS 11 PFR")

If InStr(objItem.Categories, "QUALITY FRAMEWORK") > 0 Then
Set MyItem = objItem.Copy
MyItem.Move FolderInbox.Folders("PROJECTS 12 QUALITY FRAMEWORK")

If InStr(objItem.Categories, "RECOVERY") > 0 Then
Set MyItem = objItem.Copy
MyItem.Move FolderInbox.Folders("PROJECTS 13 RECOVERY")

cMAILS.Add objItem.EntryID
End If

On Error Resume Next

Do While cMAILS.count > 0

Set MyItem = ns.GetItemFromID(cMAILS(1))

If Not MyItem Is Nothing Then
MyItem.Delete
End If

cMAILS.Remove (1)
Loop
End Sub
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
L Moving emails with similar subject and find the timings between the emails using outlook VBA macro Outlook VBA and Custom Forms 1
N How can I increase/faster outlook VBA Macro Speed ? Using Outlook 2
J Help Please!!! Outlook 2016 - VBA Macro for replying with attachment in meeting invite Outlook VBA and Custom Forms 9
M Slow VBA macro in Outlook Outlook VBA and Custom Forms 5
M Outlook VBA Macro that could retrieve/display the (From, Subject, Date Received) Outlook VBA and Custom Forms 2
Philip Rose Recreating a WORD Editing Macro to use in Outlook VBA Outlook VBA and Custom Forms 4
B Outlook vba macro Using Outlook 1
P VBA Macro for formatting multiple phone numbers in outlook contacts Using Outlook 1
C Outlook VBA - Create Macro Move Contact field Item to Another Using Outlook 1
J Outlook custom form - VBS call VBA macro Outlook VBA and Custom Forms 3
N VBA Procedure (or Macro) to Stop Outlook from Closing? Outlook VBA and Custom Forms 2
M Run external program from Outlook VBA macro Outlook VBA and Custom Forms 5
S Custom VBA forms in Outlook--how to call w/macro? Outlook VBA and Custom Forms 1
J Want to learn VBA Macros for Outlook. What book can you recommend? Outlook VBA and Custom Forms 2
M Outlook 2013 reminder email by using Outlook vba Outlook VBA and Custom Forms 2
D Outlook VBA error extracting property data from GetRules collection Outlook VBA and Custom Forms 10
O Email not leaving Outbox when using Excel VBA to sync Outlook account Outlook VBA and Custom Forms 4
B Outlook Business Contact Manager with SQL to Excel, User Defined Fields in BCM don't sync in SQL. Can I use VBA code to copy 1 field to another? BCM (Business Contact Manager) 0
N Outlook Email Rule execution through shortcut keys (VBA codes) Using Outlook 1
A VBA Code in Outlook disappears after first use Outlook VBA and Custom Forms 1
dweller Outlook 2010 Rule Ignores VBA Script Outlook VBA and Custom Forms 2
G Outlook VBA and Google Calendar ("Events") Outlook VBA and Custom Forms 1
J VBA Outlook : Subject line : Cut and Paste name to heading , number to very end of the body of Email Outlook VBA and Custom Forms 1
B Advanced Search in MS Outlook by VBA and SQL Outlook VBA and Custom Forms 2
K Outlook Archive to PST Files by Date Range VBA Script? Outlook VBA and Custom Forms 1
S Find a cell value in excel using outlook vba Using Outlook 1
J Execute Add-In Button from VBA Outlook 2016 Outlook VBA and Custom Forms 1
J Open an outlook email by Subject on MS Access linked table with VBA Outlook VBA and Custom Forms 10
D create an html table in outlook custom form 2010 using vba in MsAccess Outlook VBA and Custom Forms 7
T Outlook AntiSpam with VBA Outlook VBA and Custom Forms 1
F "Move to" O365 feature to Outlook client via VBA Outlook VBA and Custom Forms 4
B query outlook using vba Outlook VBA and Custom Forms 13
J VBA to switch Outlook online/offline Outlook VBA and Custom Forms 4
M VBA to change flag status in outlook contact item Outlook VBA and Custom Forms 3
T VBA outlook, detect priority emails Outlook VBA and Custom Forms 5
C Need VBA code to automatically save message outside outlook and add date Outlook VBA and Custom Forms 1
stephen li VBA Outlook send mail automatically by specified outlook mail box Outlook VBA and Custom Forms 1
S Outlook VBA Contacts Notes Outlook VBA and Custom Forms 0
O VBA to Run Font Change on Outlook Startup Outlook VBA and Custom Forms 4
P Outlook 2007 Email Categorization using VBA Outlook VBA and Custom Forms 1
O VBA or other solution for Outlook tasks to OneNote Outlook VBA and Custom Forms 0
S Automatically selecting folders and deleting messages in Outlook VBA Outlook VBA and Custom Forms 7
D Creating an outlook session from Access vba but run silently. With A specific profile Outlook VBA and Custom Forms 1
Diane Poremsky Outlook VBA: Use a Text File to Populate a ListBox New Slipstick.com Articles 0
C Saving Outlook attachments and links to attachments with VBA Outlook VBA and Custom Forms 2
Diane Poremsky Outlook VBA: Work with Open Item or Selected Item New Slipstick.com Articles 0
Diane Poremsky Working with VBA and non-default Outlook Folders New Slipstick.com Articles 0
C Outlook VBA to set current account Outlook VBA and Custom Forms 1
Diane Poremsky Use VBA to create an Outlook Search Folder for Sender New Slipstick.com Articles 0
F VBA routine to write new sub routine in outlook Outlook VBA and Custom Forms 0
Similar threads


















































Top