Move sent mail to sub sub folders

S

S1lverface

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
 
S

Sue Mosher [MVP-Outlook]

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")
 
S

S1lverface

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 said:
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 said:
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
 
S

Sue Mosher [MVP-Outlook]

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 said:
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 said:
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 said:
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
 

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