|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Create Macro to move email to subfolder in inboxI'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 Set inboxFolder = ns.GetDefaultFolder(olFolderInbox)
Set folder = inboxFolder.Folders("test") Set folder = folder.Folders("Retail") -- Show quoteHide quoteKen Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "dza7" <dvpe***@gmail.com> wrote in message news:b127a372-89eb-4f9c-8267-7a64df4002ed@w35g2000prg.googlegroups.com... > 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 excellent!
Thank you. Just in case it comes up, what would the code be for moving a message to a third level of folders say "Inbox/Test/Retail/Shipment" Thanks, Daniel Set folder = folder.Folders("Retail")
Set folder = folder.Folders("Shipment") See a pattern there? -- Show quoteHide quoteKen Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "dza7" <dvpe***@gmail.com> wrote in message news:71eea014-09be-4887-8292-8be2f3d8d845@u9g2000pre.googlegroups.com... > excellent! > > Thank you. > > Just in case it comes up, what would the code be for moving a message > to a third level of folders say "Inbox/Test/Retail/Shipment" > > Thanks, > > Daniel Sorry, one more thing!
How about assigning a keyboard shortcut to these marcos. For instances, I'd like to maybe change the code so that the following macro can happen when I hit the number "0" on my keyboard Sub VENT() 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("Retail") Set folder = folder.Folders("Stores") Set folder = folder.Folders("0-Ventura") 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 Not possible.
You can add a button to a toolbar to call the macro. Make sure it's a Public Sub with no input arguments. Right-click on the Outlook menu bar, select Customize. Commands tab, select Macros in the left-hand listbox. Select the macro and drag it to where you want it. You can right-click that button to rename it. -- Show quoteHide quoteKen Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "dza7" <dvpe***@gmail.com> wrote in message news:8ea9cf37-182c-42bf-99fa-014a50ba542e@w31g2000prd.googlegroups.com... > Sorry, one more thing! > > How about assigning a keyboard shortcut to these marcos. For > instances, I'd like to maybe change the code so that the following > macro can happen when I hit the number "0" on my keyboard > > > Sub VENT() > > 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("Retail") > Set folder = folder.Folders("Stores") > Set folder = folder.Folders("0-Ventura") > > > 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
Other interesting topics
Working with Outlook Contacts from Access
Start macro creating a mail with contact data and autotext Delegate Exporting Contacts using VBA? Copy message body with formatting from Outlook to Word. Inspector.WordEditor always returns null avoid syncing birthday date to calendar when saving contact Item Outlook confirmation dialog. Printing TIFF/JPG Attachment Show Sender Address in Tooltip or Customized View Redemption Error code 13 while opening addressbook - vbscript |
|||||||||||||||||||||||