PickFolder Option in Loop

Joined
Jan 30, 2008
Messages
1
Reaction score
0
Hi there, I'm new to this forum and quite inexperienced with VBA. - I'm trying to set up some code that helps me clear my Inbox regularly to a holding folder.

Ideally, I would have like to choose a date range but not getting my head around yet, I've settled for below. The code works but I need to pick the folder for each message that is moved which is not really automated.

I've tried to declare the Folder as "Dim objFolder As MAPIFolder" and and "Set objFolder = ns.PickFolder" but that doesn't work. How can I pick a folder once and tell it to use this folder for the entire loop? - If anybody has a good idea for picking a date range, I would be grateful for that as well!

Thanks!

Dim ns As NameSpace
Dim objInbox As MAPIFolder
Dim objSentItems As MAPIFolder
Set ns = ThisOutlookSession.Session
Set objInbox = ns.GetDefaultFolder(olFolderInbox)
Set objSentItems = ns.GetDefaultFolder(olFolderSentMail)

Dim msg As MailItem
'Run through each item in the Inbox
For Each msg In objInbox.Items
'Look for messages received more than 45 days before current date
If msg.ReceivedTime < Date - 45 Then
msg.Move ns.PickFolder 'need to identify folder
End If
Next
'Run through each item in the Inbox
For Each msg In objSentItems.Items
'Look for message sent more than 45 days before current date
If msg.SentOn < Date - 45 Then
msg.Move ns.PickFolder 'need to identify folder
End If
Next
 
Back
Top