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

Move sent mail to sub sub folders



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old April 22nd 08, 08:39 PM posted to microsoft.public.outlook.program_vba
S1lverface
external usenet poster
 
Posts: 8
Default Move sent mail to sub sub folders


In my Sent Items I have a Subfolder called LEVEL 1. Below this I drill down
to a sub subfolder called Level 1.1. I want the code below to move mail from
Sent Items box to the Level 1.1 Folder but it doesn't find the folder,
although it exists

Can you help?

Thanks
S1lverface
_________

Sub MoveSentItems()

Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.MAPIFolder
Dim myDestFolder As Outlook.MAPIFolder
Dim myItems As Outlook.Items
Dim myItem As Object
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderSentMail)
Set myItems = myInbox.Items

Set myDestFolder = myInbox.Folders("Level 1.1")
Set myItem = myItems.Find("[To] = 'John Brody'")
While TypeName(myItem) "Nothing"
myItem.Move myDestFolder
Set myItem = myItems.FindNext
Wend


End Sub




  #2  
Old April 22nd 08, 08:59 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Move sent mail to sub sub folders

Your code never accesses the Level 1 folder and therefore, can't locate its Level 1.1 subfolder.

Set myInbox = myNameSpace.GetDefaultFolder(olFolderSentMail)
Set myLevel1 = myInbox.Folders("Level 1")
Set myDestFolder = myLevel1.Folders("Level 1.1")

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"S1lverface" wrote in message ...

In my Sent Items I have a Subfolder called LEVEL 1. Below this I drill down
to a sub subfolder called Level 1.1. I want the code below to move mail from
Sent Items box to the Level 1.1 Folder but it doesn't find the folder,
although it exists

Can you help?

Thanks
S1lverface
_________

Sub MoveSentItems()

Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.MAPIFolder
Dim myDestFolder As Outlook.MAPIFolder
Dim myItems As Outlook.Items
Dim myItem As Object
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderSentMail)
Set myItems = myInbox.Items

Set myDestFolder = myInbox.Folders("Level 1.1")
Set myItem = myItems.Find("[To] = 'John Brody'")
While TypeName(myItem) "Nothing"
myItem.Move myDestFolder
Set myItem = myItems.FindNext
Wend


End Sub




  #3  
Old April 23rd 08, 12:32 AM posted to microsoft.public.outlook.program_vba
S1lverface
external usenet poster
 
Posts: 8
Default Move sent mail to sub sub folders

Perfect. Thanks very much.

I've noticed that if I have sent an e-mail to more than one recipient, then
this code does not move the mail.

Is there code you can help me with that will, in the event of there being
more than one reipient, it will move the mail to the sub folder of the first
person on the list (or a copy of the mail to the correct folder of every
recipient, for which I have a sub subfolder)

Thanks again.
silverface.

"Sue Mosher [MVP-Outlook]" wrote:

Your code never accesses the Level 1 folder and therefore, can't locate its Level 1.1 subfolder.

Set myInbox = myNameSpace.GetDefaultFolder(olFolderSentMail)
Set myLevel1 = myInbox.Folders("Level 1")
Set myDestFolder = myLevel1.Folders("Level 1.1")

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"S1lverface" wrote in message ...

In my Sent Items I have a Subfolder called LEVEL 1. Below this I drill down
to a sub subfolder called Level 1.1. I want the code below to move mail from
Sent Items box to the Level 1.1 Folder but it doesn't find the folder,
although it exists

Can you help?

Thanks
S1lverface
_________

Sub MoveSentItems()

Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.MAPIFolder
Dim myDestFolder As Outlook.MAPIFolder
Dim myItems As Outlook.Items
Dim myItem As Object
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderSentMail)
Set myItems = myInbox.Items

Set myDestFolder = myInbox.Folders("Level 1.1")
Set myItem = myItems.Find("[To] = 'John Brody'")
While TypeName(myItem) "Nothing"
myItem.Move myDestFolder
Set myItem = myItems.FindNext
Wend


End Sub





  #4  
Old April 23rd 08, 12:52 AM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Move sent mail to sub sub folders

That's because your code looks for an exact match:

Set myItem = myItems.Find("[To] = 'John Brody'"

If you want to do something more complex, you can iterate the entire myItems collection and use Instr() to see if John Brody is present in the To field. Or, iterate the Recipients collection of each item.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"S1lverface" wrote in message ...
Perfect. Thanks very much.

I've noticed that if I have sent an e-mail to more than one recipient, then
this code does not move the mail.

Is there code you can help me with that will, in the event of there being
more than one reipient, it will move the mail to the sub folder of the first
person on the list (or a copy of the mail to the correct folder of every
recipient, for which I have a sub subfolder)

Thanks again.
silverface.

"Sue Mosher [MVP-Outlook]" wrote:

Your code never accesses the Level 1 folder and therefore, can't locate its Level 1.1 subfolder.

Set myInbox = myNameSpace.GetDefaultFolder(olFolderSentMail)
Set myLevel1 = myInbox.Folders("Level 1")
Set myDestFolder = myLevel1.Folders("Level 1.1")

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"S1lverface" wrote in message ...

In my Sent Items I have a Subfolder called LEVEL 1. Below this I drill down
to a sub subfolder called Level 1.1. I want the code below to move mail from
Sent Items box to the Level 1.1 Folder but it doesn't find the folder,
although it exists

Can you help?

Thanks
S1lverface
_________

Sub MoveSentItems()

Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.MAPIFolder
Dim myDestFolder As Outlook.MAPIFolder
Dim myItems As Outlook.Items
Dim myItem As Object
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderSentMail)
Set myItems = myInbox.Items

Set myDestFolder = myInbox.Folders("Level 1.1")
Set myItem = myItems.Find("[To] = 'John Brody'")
While TypeName(myItem) "Nothing"
myItem.Move myDestFolder
Set myItem = myItems.FindNext
Wend


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
How can I move a BUNCH of folders from one PST to another? Bruce Outlook and VBA 0 January 20th 08 08:52 PM
How do you move OE folders from XP to Vista Windows Mail Marty in GA Outlook - General Queries 1 April 17th 07 04:34 PM
How to Move Mail Folders Between Two Computers Running OE 6 sheana Outlook Express 5 November 26th 06 09:48 PM
Macro to Move Mail Messages from Draft folder to other folders VBnovice Outlook and VBA 4 June 14th 06 07:10 PM
How to move folders to another drive Fred Outlook Express 6 April 19th 06 09:42 PM


All times are GMT +1. The time now is 12:49 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.