A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

moving email to subfolder



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 4th 07, 11:41 AM posted to microsoft.public.outlook.program_vba
robin
external usenet poster
 
Posts: 53
Default moving email to subfolder

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.
  #2  
Old May 4th 07, 05:34 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default moving email to subfolder

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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Robin" wrote in message
...
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.


  #3  
Old May 11th 07, 10:27 AM posted to microsoft.public.outlook.program_vba
robin
external usenet poster
 
Posts: 53
Default moving email to subfolder

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

"Ken Slovak - [MVP - Outlook]" wrote:

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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Robin" wrote in message
...
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.



  #4  
Old May 11th 07, 03:59 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default moving email to subfolder

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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Robin" wrote in message
...
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


  #5  
Old May 14th 07, 08:12 AM posted to microsoft.public.outlook.program_vba
robin
external usenet poster
 
Posts: 53
Default moving email to subfolder

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.

"Ken Slovak - [MVP - Outlook]" wrote:

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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Robin" wrote in message
...
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



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Rules duplicating email instead of moving Bob Levine Outlook - General Queries 5 November 4th 06 02:32 PM
moving contacts list to the tool bar and to: on new email Frank T Outlook - Using Contacts 2 August 17th 06 04:56 PM
Moving Outlook to another PC, and moving data files to another location /mel/ Outlook - General Queries 3 June 24th 06 04:39 PM
Moving Specific Inbox Items to a Specific Subfolder (VBA) DevDaniel Outlook and VBA 1 April 11th 06 06:46 AM
MOVING EMAIL BETWEEN DRIVES IDIDIT Outlook - General Queries 1 January 30th 06 03:49 AM


All times are GMT +1. The time now is 07:07 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.