Moving Message Class email via script and Rule

Liams Sot

New Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
#1
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
 

Liams Sot

New Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
#3
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
#4
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.
 
Top