Moving Message Class email via script and Rule

Status
Not open for further replies.

Liams Sot

New Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
I am trying to move a particular message class to the deleted folders as soon as it arrives in the mailbox.
The script works but throws out an error - 91 with Line Set objItem = objOutlook.ActiveInspector.CurrentItem. I can't figure out where my issues are. I also want to add the OL for automatic reply for out of office email. Anyone have an answer?


Code:
Sub MoveMessageClass(Item As Outlook.MailItem)
'Move email to the deleted items folder if it is of a particular message class
 
    Dim objOutlook As Outlook.Application
    Dim objNamespace As Outlook.NameSpace
    Dim objSourceFolder As Outlook.MAPIFolder
    Dim objDestFolder As Outlook.MAPIFolder
    Dim objItem As MailItem
   
' Housekeeping: set up the macro environment
    Set objOutlook = Application
    Set objNamespace = objOutlook.GetNamespace("MAPI")
    Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderInbox)
    Set objDestFolder = objNamespace.GetDefaultFolder(olFolderDeletedItems)
   ' Set objItem = objSourceFolder.Items
 
' Item inspection
    Set objItem = objOutlook.ActiveInspector.CurrentItem
  
       
' Move objItems with the message classes in the CASE
    Select Case objItem
    Case olMeetingResponseNegative, olMeetingResponsePositive, olMeetingRequest, olMeetingAccepted, olMeetingTentative
    objItem.Move objDestFolder
    End Select
 
 
End Sub
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
The error means there's no active inspector. You want to run the code on the Item object that's already passed by the rule, so use that variable instead of objItem.
 

Liams Sot

New Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
Reply thanks... I am not sure which variable that is - I am new to VBA and usually don't script normally. Would that be the Outlook.MailItem?
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
See the first line:
Sub MoveMessageClass(Item As Outlook.MailItem)

'Item' is the name of the variable, 'Outlook.MailItem' is the type. The name is used to do anything with the object (email in this case). This variable is set by the rule, it points to the email that triggered the rule.

Delete your declaration of the objItem variable, and replace the other objItem in the code by Item.

Also, this makes no sense:
Code:
' Move objItems with the message classes in the CASE
    Select Case objItem
    Case olMeetingResponseNegative, olMeetingResponsePositive, olMeetingRequest, olMeetingAccepted, olMeetingTentative
First, if you want to check a property of the object, you need to write it:
Code:
select case item.class
Second, if you want to move meeting items, the variable in the first line must be declared as MeetingItem, not as MailItem.
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
A Outlook 2013 EAS: moving message causes duplicates Using Outlook 3
Commodore Message becomes "unread" after moving to a local folder Using Outlook 2
M Preventing conversation from moving to the top of the message box? Using Outlook 7
L check if send message appears in SendItems forder before moving Using Outlook 0
D while moving a read e-mail message to my folder, the folder disapeared with all the messages stored Using Outlook 2
B Moving to next message closes message window Using Outlook 1
J moving a message from identified sender to another folder Outlook VBA and Custom Forms 5
J Moving Imported folder Using Outlook 2
J Outlook 2016 Moving IMAP emails to Exchange Using Outlook 1
A .restrict results changing after moving to Exchange online Outlook VBA and Custom Forms 0
T I'm thinking about moving from outlook.com to the Outlook I have in my Office 365 Using Outlook 1
L Moving emails with similar subject and find the timings between the emails using outlook VBA macro Outlook VBA and Custom Forms 1
S Moving .OST file location unsuccessful! Using Outlook 6
M Moving mail to another folder is much slower than before (Office365) Using Outlook 0
D Any updates or fixes that would make this code stop working just moving emails to another folder Outlook VBA and Custom Forms 1
B Moving account, contacts & emails to another H/D with MSOutlook Using Outlook 5
M I'm Having problems Moving Contacts to a New List Using Outlook 8
D Moving Emails Based on Recipient/Sender Outlook VBA and Custom Forms 4
U Outlook 2010 'freezes' before moving emails Using Outlook 2
S Moving Emails Between Archive Folders Using Outlook 1
P Moving Outlook.pst & archive1.pst Using Outlook 3
A Moving archived contents in Outlook 2007 back into working folders Using Outlook 0
Diane Poremsky Moving Deleted Items New Slipstick.com Articles 0
O Moving .ost file Using Outlook 12
Diane Poremsky Outlook.com is moving to Office 365! New Slipstick.com Articles 3
Diane Poremsky Check Contacts before moving them to Hotmail Contacts folder New Slipstick.com Articles 0
V Problem moving folders Using Outlook 4
Diane Poremsky Moving Outlook to a New Computer New Slipstick.com Articles 0
Diane Poremsky Moving from Outlook Express to Outlook New Slipstick.com Articles 0
M1ck53 Moving Outlook Using Outlook 9
Diane Poremsky Moving an Outlook offline data file (*.ost) New Slipstick.com Articles 3
D After Moving or Deleting Open Item - Meeting Requests Using Outlook 4
E Moving autoarchive settings to new computer (Outlook 2007) Using Outlook 1
Nick Truscott Lost custom forms after moving mailbox Outlook VBA and Custom Forms 3
R Moving contacts from ICloud back to Outlook 2010 Using Outlook 4
M which Outlook recommended to buy for moving Outlook 2000 versions Contact Data Using Outlook 2
P Moving PST file questions Using Outlook 3
Klaas "To Address" duplicated when moving msg to another folder Using Outlook 2
C Moving BCM Database to Server Share BCM (Business Contact Manager) 1
A Moving .msg files back into outlook Using Outlook 2
S automatically moving flagged sent e-mail to a special folder Outlook VBA and Custom Forms 1
M moving custom field data between outlook and excel? Using Outlook 4
G Moving "Delete" button on Outlook for Mac Using Outlook 1
S Moving folders from outlook 2010 to a new computer with outlook 2013 Using Outlook 1
W Moving Exchange 2007 to a different drive/partition? Exchange Server Administration 1
A Outlook VBA - moving mail item to public folder using variable within path Using Outlook 6
O New to Outlook 2013, dealing with copying vs. moving sent items Using Outlook 0
C Cant find emails after moving pst Using Outlook 1
O Moving OUtlook 2003 from bad XP to Win 7 Pro 64 -- URGENT! Using Outlook 8
P Outlook 2013 rules -- not working reliably -- moving messages to wrong boxes Using Outlook 0
Similar threads


















































Top