moving email to subfolder

G

Guest

Hi. I have a macro (generously donated by Ken) which I have adapted to move a
throw-away email that I am sending to a temporary folder. The line:
objInbox.Folders("Temp Sent") does the job, but the folder is not in the
right place. I would like this Temp Sent folder to be a subfolder to the
standard Sent Items folder. Any ideas on the change to the syntax? Thanks.
 
K

Ken Slovak - [MVP - Outlook]

Dim oSent As Outlook.MAPIFolder
Set oSent = oNS.GetDefaultFolder(olFolderSentMail)
oSent.Folders("Temp Sent")

Of course you have to create that folder there before the code will work.
 
G

Guest

Thanks Ken! The procedure works great on new emails, but I now have a problem
with "reply" and "forward" emails (very strange!). An error message comes up:
"Send operation failed because item was deleted before it was sent". Any
ideas? My code so far:

Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim answer As Long
Dim objFolder As Outlook.MAPIFolder
Dim oSent As Outlook.MAPIFolder
Dim objNS As Outlook.NameSpace

If Item.Class = olMail Then
answer = MsgBox("SAVE subj: " & _
Item.Subject & " to Sent Items?", vbYesNo)
If answer = vbNo Then

On Error Resume Next
Set objNS = Application.GetNamespace("MAPI")
Set oSent = objNS.GetDefaultFolder(olFolderSentMail)
Set objFolder = oSent.Folders("Temp Sent")

If objFolder Is Nothing Then
MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation,
"INVALID FOLDER"
End If

If Application.ActiveInspector Is Nothing Then
'Require that this procedure be called for an open item
Exit Sub
End If

If Application.ActiveInspector.CurrentItem.Class <> olMail Then
Exit Sub
End If

Application.ActiveInspector.CurrentItem.Move objFolder

Set objFolder = Nothing
Set oSent = Nothing
Set objNS = Nothing

Item.DeleteAfterSubmit = True

End If
End If
End Sub
 
K

Ken Slovak - [MVP - Outlook]

You can't move an item in ItemSend or you get the error you're getting.

In this case I'd not do that but instead I'd set SaveSentMessageFolder:

Set Item.SaveSentMessageFolder = objFolder

That will save the item when the send is complete to the designated folder
automatically with no further intervention from you.
 
G

Guest

Thanks a lot, Ken, that seems to work perfectly now. Just to confirm: I
replaced Item.DeleteAfterSubmit = True with Set Item.SaveSentMessageFolder =
objFolder.
Regards, Robin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top