C
cirrus
Hi all, I've used the code below in 2003 to copy sent items into my
Inbox (and also mark deleted items as read, but that part is OK). I've
upgraded to 2007, and now when I send an emial it throws the error
"Run-time error '-2147221241 (80040107)" and the debugger takes me to
the line "Set objItemCopy = Item.Copy".
Some odd things: The first time I send an email after opening Outlook,
it gives the error but the email is moved to the inbox. Subsequent
emails don't seem to run the code. Also, if I put a breakpoint on the
line in question and step through the function, it works without any
errors - and it continues to work for the subsequent emails, as long
as I step through using the debugger.
Thanks for your help!!
Regards,
ES
Option Explicit
Dim objInbox As Outlook.MAPIFolder
Dim WithEvents objDeletedItems As Outlook.Items
Dim WithEvents objSentItems As Outlook.Items
Private Sub Application_Startup()
Dim objNS As Outlook.NameSpace
Set objNS = Application.GetNamespace("MAPI")
'objInbox was declared with module scope
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Dim objDeleted As Outlook.MAPIFolder
Set objDeleted = objNS.GetDefaultFolder(olFolderDeletedItems)
Set objDeletedItems = objDeleted.Items
Dim objSent As Outlook.MAPIFolder
Set objSent = objNS.GetDefaultFolder(olFolderSentMail)
Set objSentItems = objSent.Items
End Sub
Private Sub objDeletedItems_ItemAdd(ByVal Item As Object)
Item.UnRead = False
Item.Save
End Sub
Private Sub objSentItems_ItemAdd(ByVal Item As Object)
Dim objItemCopy As Object
Set objItemCopy = Item.Copy
objItemCopy.Move objInbox
End Sub
Inbox (and also mark deleted items as read, but that part is OK). I've
upgraded to 2007, and now when I send an emial it throws the error
"Run-time error '-2147221241 (80040107)" and the debugger takes me to
the line "Set objItemCopy = Item.Copy".
Some odd things: The first time I send an email after opening Outlook,
it gives the error but the email is moved to the inbox. Subsequent
emails don't seem to run the code. Also, if I put a breakpoint on the
line in question and step through the function, it works without any
errors - and it continues to work for the subsequent emails, as long
as I step through using the debugger.
Thanks for your help!!
Regards,
ES
Option Explicit
Dim objInbox As Outlook.MAPIFolder
Dim WithEvents objDeletedItems As Outlook.Items
Dim WithEvents objSentItems As Outlook.Items
Private Sub Application_Startup()
Dim objNS As Outlook.NameSpace
Set objNS = Application.GetNamespace("MAPI")
'objInbox was declared with module scope
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Dim objDeleted As Outlook.MAPIFolder
Set objDeleted = objNS.GetDefaultFolder(olFolderDeletedItems)
Set objDeletedItems = objDeleted.Items
Dim objSent As Outlook.MAPIFolder
Set objSent = objNS.GetDefaultFolder(olFolderSentMail)
Set objSentItems = objSent.Items
End Sub
Private Sub objDeletedItems_ItemAdd(ByVal Item As Object)
Item.UnRead = False
Item.Save
End Sub
Private Sub objSentItems_ItemAdd(ByVal Item As Object)
Dim objItemCopy As Object
Set objItemCopy = Item.Copy
objItemCopy.Move objInbox
End Sub