![]() |
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. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
I have some code that I've attach to a menu button that will
move a selected email to a hard coded predefined folder. I would like the code to look at the ReceivedTime of the selected email and set the target objFolder to based on the ReceivedTime. If the ReceivedTime is say '01/02/2007 03:35:40 PM' I want to set the objFolder to 200702-In. I can get the folder name with the following line of code: sbDateStr = Mid(objItem.ReceivedTime, 7, 4) & Mid (objItem.ReceivedTime, 4, 2) & "-In" I just can't figure out how to set objFolder to the value stored in sbDateStr. I'd also like to have an error routine to detect if 200702-In exists before attempting t move the email. Here's the code I have so far. Sub sbmovemsgs() Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem Dim sbDateStr As String Set objNS = Application.GetNamespace("MAPI") Set objInbox = objNS.GetDefaultFolder(olFolderInbox) Set objFolder = Application.GetNamespace("MAPI").Folders("Personal Folders").Folders("200707-In") 'Set objFolder = objInbox.Parent.Folders("Stuart") 'Assume this is a mail folder If objFolder Is Nothing Then MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER" End If If Application.ActiveExplorer.Selection.Count = 0 Then 'Require that this procedure be called only when a message is selected Exit Sub End If For Each objItem In Application.ActiveExplorer.Selection If objFolder.DefaultItemType = olMailItem Then If objItem.Class = olMail Then objItem.Move objFolder 'how do I set objFolder to the value in sbDateStr below 'sbDateStr = Mid(objItem.ReceivedTime, 7, 4) & Mid(objItem.ReceivedTime, 4, 2) & "-In" End If End If Next Set objItem = Nothing Set objFolder = Nothing Set objInbox = Nothing Set objNS = Nothing End Sub Thanks Stu |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Move email messages to a specified folder based on a category | DougLost | Outlook and VBA | 2 | October 7th 10 03:18 PM |
A rule for creating a folder based on sender's name and move messages to it | hprod | Outlook - General Queries | 3 | February 21st 07 11:21 PM |
move msgs based on one website | Move msgs based on website | Outlook - Using Contacts | 0 | November 30th 06 10:28 AM |
Move emails to a folder rule (Time based) | George Lake | Outlook - General Queries | 1 | April 27th 06 03:09 PM |
Move mail to a folder based on 2 different words in the subject fi | Alan Kirkham | Outlook and VBA | 2 | February 14th 06 02:34 PM |