dza7
2009-04-15 02:10:17 UTC
Hello,
I'm attempting to create a macro in Outlook moving a message from my
inbox to a subfolder in my inbox, say for example this subfolder is
located in "Inbox/Test/Retail"
I found the code to move a message to "Inbox/Test" but I can't figure
out how to change the code so it can move the message to "Inbox/Test/
Retail".
Can someone help me move the message to a second layer of folders in
my inbox?
Here is the code I have now:
Sub move()
On Error Resume Next
Dim folder As Outlook.MAPIFolder, inboxFolder As
Outlook.MAPIFolder
Dim ns As Outlook.NameSpace, objItem As Outlook.MailItem
Set ns = Application.GetNamespace("MAPI")
Set inboxFolder = ns.GetDefaultFolder(olFolderInbox)
Set folder = inboxFolder.Folders("//inbox/test")
If Application.ActiveExplorer.Selection.Count = 0 Then
Exit Sub
End If
If folder Is Nothing Then
MsgBox "oops, no folder!", vbOKOnly + vbExclamation, "you're a
bad bad man"
End If
For Each objItem In Application.ActiveExplorer.Selection
If folder.DefaultItemType = olMailItem Then
If objItem.Class = olMail Then
objItem.move folder
End If
End If
Next
Set objItem = Nothing
Set folder = Nothing
Set inboxFolder = Nothing
Set ns = Nothing
End Sub
Thanks,
Dza
I'm attempting to create a macro in Outlook moving a message from my
inbox to a subfolder in my inbox, say for example this subfolder is
located in "Inbox/Test/Retail"
I found the code to move a message to "Inbox/Test" but I can't figure
out how to change the code so it can move the message to "Inbox/Test/
Retail".
Can someone help me move the message to a second layer of folders in
my inbox?
Here is the code I have now:
Sub move()
On Error Resume Next
Dim folder As Outlook.MAPIFolder, inboxFolder As
Outlook.MAPIFolder
Dim ns As Outlook.NameSpace, objItem As Outlook.MailItem
Set ns = Application.GetNamespace("MAPI")
Set inboxFolder = ns.GetDefaultFolder(olFolderInbox)
Set folder = inboxFolder.Folders("//inbox/test")
If Application.ActiveExplorer.Selection.Count = 0 Then
Exit Sub
End If
If folder Is Nothing Then
MsgBox "oops, no folder!", vbOKOnly + vbExclamation, "you're a
bad bad man"
End If
For Each objItem In Application.ActiveExplorer.Selection
If folder.DefaultItemType = olMailItem Then
If objItem.Class = olMail Then
objItem.move folder
End If
End If
Next
Set objItem = Nothing
Set folder = Nothing
Set inboxFolder = Nothing
Set ns = Nothing
End Sub
Thanks,
Dza