Sue,
Can you tell me what is wrong with my code below? I cannot seem to figure
out the right way to reference the SenderName value. It keeps throwing the
following error for line 9.
Run-time error '91':
Object variable or With block variable not set
'__________________________________________________________________________________
Sub MoveSelectedMessagesToFolder()
On Error Resume Next
Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder
Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem
Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Set objFolder =
Outlook.Session.Folders("2007").Folders(objItem.SenderName)
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
End If
End If
Next
Set objItem = Nothing
Set objFolder = Nothing
Set objInbox = Nothing
Set objNS = Nothing
End Sub
'__________________________________________________________________________________
Session.Folders returns the collection of top-level folders, i.e. all the
individual .pst files or mailboxes. To get a non-default folder, you need to
walk the folder hierarchy starting with that collections or use a function
that does that for you. See
http://www.outlookcode.com/d/code/getfolder.htm
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers