EvilRedSmurf
09-11-2013, 04:05 AM
Hi,
I (with a little help) set up a macro to go through the items in my inbox and, if any message satisfied 2 conditions, copy the message to a folder before deleting the message. My macro worked perfectly for several months before going wrong at the end of last week. I've tried to work out what the error is myself without success. If anyone could help me I would be most grateful.
The error I'm getting is Run Time Error 438 Object doesn't support this property or method error and the debug highlights the line highlighted in the code below:
Sub MoveToFolder2()
Dim ns As Outlook.NameSpace
Dim objItem As Object
Dim FolderInbox As Folder
Dim MyItem As Outlook.MailItem
Dim cMails As Collection
Set ns = Application.GetNamespace("MAPI")
Set FolderInbox = ns.GetDefaultFolder(olFolderInbox)
Set cMails = New Collection
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''
For Each objItem In FolderInbox.Items
If objItem.FlagStatus = 1 and objItem.ReceivedTime < Now - 5 Then '''''''''''''''''''''''''''''''''''ERROR APPEARS HERE''''''''''''''''''''''''''''''''''''''''
If InStr(objItem.Categories, "B&C Limited") > 0 Then
Set MyItem = objItem.Copy
MyItem.Move FolderInbox.Folders("B&C")
cMails.Add objItem.EntryID
Else
End If
If InStr(objItem.Categories, "Villa Costs") > 0 Then
Set MyItem = objItem.Copy
MyItem.Move FolderInbox.Folders("Villa Costs")
cMails.Add objItem.EntryID
Else
End If'
objItem.Delete
Else
End If
Next
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
As I said, I've tried multiple changes to the limit of my vba knowledge without success - If anyone could help me I'd be very grateful.
Thanks,
Evil Red Smurf
I (with a little help) set up a macro to go through the items in my inbox and, if any message satisfied 2 conditions, copy the message to a folder before deleting the message. My macro worked perfectly for several months before going wrong at the end of last week. I've tried to work out what the error is myself without success. If anyone could help me I would be most grateful.
The error I'm getting is Run Time Error 438 Object doesn't support this property or method error and the debug highlights the line highlighted in the code below:
Sub MoveToFolder2()
Dim ns As Outlook.NameSpace
Dim objItem As Object
Dim FolderInbox As Folder
Dim MyItem As Outlook.MailItem
Dim cMails As Collection
Set ns = Application.GetNamespace("MAPI")
Set FolderInbox = ns.GetDefaultFolder(olFolderInbox)
Set cMails = New Collection
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''
For Each objItem In FolderInbox.Items
If objItem.FlagStatus = 1 and objItem.ReceivedTime < Now - 5 Then '''''''''''''''''''''''''''''''''''ERROR APPEARS HERE''''''''''''''''''''''''''''''''''''''''
If InStr(objItem.Categories, "B&C Limited") > 0 Then
Set MyItem = objItem.Copy
MyItem.Move FolderInbox.Folders("B&C")
cMails.Add objItem.EntryID
Else
End If
If InStr(objItem.Categories, "Villa Costs") > 0 Then
Set MyItem = objItem.Copy
MyItem.Move FolderInbox.Folders("Villa Costs")
cMails.Add objItem.EntryID
Else
End If'
objItem.Delete
Else
End If
Next
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
As I said, I've tried multiple changes to the limit of my vba knowledge without success - If anyone could help me I'd be very grateful.
Thanks,
Evil Red Smurf