PDA

View Full Version : Copy Outlook Items To Multiple Folders



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

skatonni
09-11-2013, 02:35 PM
Run Time Error 438 Object doesn't support this property or method error
The object which is objItem does not support either FlagStatus or ReceivedTime (or both).


For Each objItem In FolderInbox.Items
If TypeOf objItem Is mailItem Then

EvilRedSmurf
09-12-2013, 12:20 AM
Run Time Error 438 Object doesn't support this property or method error
The object which is objItem does not support either FlagStatus or ReceivedTime (or both).


For Each objItem In FolderInbox.Items
If TypeOf objItem Is mailItem Then


Many thanks for that I see what you mean. It is now skipping over that section of the code and highlighting a line near the end:

cMails.remove
do you know why it would be highlighting this line (in my original code above I had (1) loop on the end - this was my mistake loop is on a different line and the (1) should not be there at all)

Many thanks in advance

EvilRedSmurf
09-12-2013, 12:42 AM
Many thanks for that I see what you mean. It is now skipping over that section of the code and highlighting a line near the end:

cMails.remove
do you know why it would be highlighting this line (in my original code above I had (1) loop on the end - this was my mistake loop is on a different line and the (1) should not be there at all)

Many thanks in advance

Sorry I didn't tell you what the error was - it says:
Compile Error: Argument not optional
Many thanks,

soha
09-18-2013, 10:21 PM
Those are some really attractive deals..i hope they are pretty authentic.

skatonni
09-21-2013, 10:15 AM
Sorry I didn't tell you what the error was - it says:
Compile Error: Argument not optional
Many thanks,

Try

End If
cMails.Remove (1)
Loop
End Sub
http://msdn.microsoft.com/en-us/library/office/gg264484.aspx