Set objFolder = objNS.Folders("2010").Folders.Item("Inbox")2010 is the PST folder name in the Outlook folder pane, and Inbox is the folder beneath it. This syntax allows a mail to be moved from the Exchange Inbox to the 2010\Inbox folder.
http://www.yeraze.com/2008/04/outlook-macro-move-to-specified-folder-mark-as-read/
Sub moveArchive()
On Error Resume Next
Dim objFolder As Outlook.MAPIFolder
Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItemFor Each objItem In Application.ActiveExplorer.Selection
If objFolder.DefaultItemType = olMailItem Then
If objItem.Class = olMail Then
objItem.UnRead = False
objItem.Move objFolder
End If
End If
Next
Set objNS = Application.GetNamespace("MAPI")
Set objFolder = objNS.Folders("2010").Folders.Item("Inbox")
'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
Set objItem = Nothing
Set objFolder = Nothing
Set objNS = Nothing
End Sub
No comments:
Post a Comment