![]() |
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
|
|||
|
|||
![]()
Eric,
And here we have more living proof that archiving older posts can certainly be helpful. This is exactly what I needed, as well ...... 4 years later. Works like a charm in Office 2007. ;-) Thanks! You just saved me some coding legwork. Alex Craig "Eric Legault [MVP - Outlook]" wrote: Okay, now that I know exactly what you want, I've altered the macro to handle any selected messages in the current folder, and to look for the folder name that you specify underneath the root of the same store containing your Inbox: 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 = objInbox.Parent.Folders("Some Folder Under The Root") '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 End If End If Next Set objItem = Nothing Set objFolder = Nothing Set objInbox = Nothing Set objNS = Nothing End Sub -- Eric Legault - B.A, MCP, MCSD, Outlook MVP -------------------------------------------------- {Private e-mails ignored} Job: http://www.imaginets.com Blog: http://blogs.officezealot.com/legault/ "Jim Johnson - Serenity Consulting" wrote: Thanks for your help Eric. Your macro doesn't quite do what I want - but it is very close! I'll use it as a basis when I get around to dusting off my VBA programming skills. The destination folder is not under the Inbox, but co-equal in the folder tree (a minor issue). The other is that I use the preview panel and only fully open a message when absolutely necessary. I need to run the macro against the selected message in the current mail folder. Meanwhile I'll have to use the two step "Move to another folder" then select the intended folder. Thanks for trying. "Eric Legault [MVP - Outlook]" wrote: If your goal was not to "reinvent" a macro but to have it automatically created for you, then of course you are out of luck because there is no macro recorder in Outlook. The only recourse we have is to hand-roll our own solutions, which isn't terribly difficult with Outlook VBA, and that's where this newsgroup comes in for assisting people who are having problems taming the Outlook programming model beast. I thought you had already begun the process of coding the solution, so I gave you a quick pointer rather than write the code for you. Regardless, below is the solution to your issue that I can share with you - it took all of five minutes. It assumes the destination folder is under your Inbox, but you can always tweak it for another location. Sub MoveOpenedMessageToFolder() On Error Resume Next Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder Dim objNS As Outlook.NameSpace Set objNS = Application.GetNamespace("MAPI") Set objInbox = objNS.GetDefaultFolder(olFolderInbox) Set objFolder = objInbox.Folders("Some Folder Under The 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.ActiveInspector Is Nothing Then 'Require that this procedure be called for an open item Exit Sub End If If Application.ActiveInspector.CurrentItem.Class olMail Then Exit Sub End If Application.ActiveInspector.CurrentItem.Move objFolder Set objFolder = Nothing Set objInbox = Nothing Set objNS = Nothing End Sub -- Eric Legault - B.A, MCP, MCSD, Outlook MVP -------------------------------------------------- {Private e-mails ignored} Job: http://www.imaginets.com Blog: http://blogs.officezealot.com/legault/ "Jim Johnson - Serenity Consulting" wrote: Not functionality - there is only one action. You missed the point. The goal was to NOT reinvent a complete macro - just paste it all in. Your one line may help me figure out which method is needed, but it sure as heck isn't a complete macro. Oh well, thanks anyhow - when I have some extra time I'll re-teach myself VBA. "Eric Legault [MVP - Outlook]" wrote: What functionality remains to be added to make the macro complete for you? -- Eric Legault - B.A, MCP, MCSD, Outlook MVP -------------------------------------------------- {Private e-mails ignored} Job: http://www.imaginets.com Blog: http://blogs.officezealot.com/legault/ "Jim Johnson - Serenity Consulting" wrote: Well thanks, but that is only half the answer I was looking for. I know about the 'Move to Folder' option. It is what I am doing now and takes twice as much work as I am looking for because you have to both select the function, then select the destination. And yes, I am looking to move these items every time to the same folder using an icon or keyboard shortcut. As for the macro - thanks for the key piece - but I believe it takes a bit more code to complete the macro. In every other Office app, I could simply record a function this simple and be done - but NOT in Outlook. I am capable of hand writing my own VBA routine, but as I don't routinely do this, it always takes me much longer than necessary. I was hoping somebody out there had already invented this wheel and would be willing to share. "Eric Legault [MVP - Outlook]" wrote: If you are essentially just moving the message rather than deleting it, would using the File - Move To Folder... command inside the message (or right-click the message, Move To Folder... / Edit - Move To Folder... in the folder view) be sufficient for your needs? If it is the same folder you are always moving the message to, you can use the Item.Move(DestinationFolder As MAPIFolder Object) method to move the message to a previously declared MAPIFolder variable. -- Eric Legault - B.A, MCP, MCSD, Outlook MVP -------------------------------------------------- {Private e-mails ignored} Job: http://www.imaginets.com Blog: http://blogs.officezealot.com/legault/ "Jim Johnson - Serenity Consulting" wrote: I need a second message 'delete' button that doesn't truly delete a message but moves it to a specified folder. Has anyone already written an Outlook 2003 macro to do this? (Why Microsoft refuses to put a 'learn' function into Outlook to jump start macro building is beyond me.) The reason is that I concurrently manage two on-line 'personalities' for different employers and do not want the messages from one personality auto-archived to the other personality's archive files. I can auto-segregate incoming messages by email account, I can auto-segregate out-going messages by email account using the Rules Wizard - but I cannot do this with deleted messages. (for legal reasons, I never actually delete anything). |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
create a macro to move outlook 2003 message to a specific fold | robin | Outlook and VBA | 0 | May 4th 07 12:09 PM |
Macro to create new email message with different account as sender | Brian Beck | Outlook and VBA | 1 | March 22nd 07 12:15 AM |
How ...When i move a message to a specific map... | Ikku de Dikku | Outlook - General Queries | 3 | September 21st 06 02:26 PM |
Macro to foward just a specific part of an email body of message | [email protected] | Outlook and VBA | 6 | August 21st 06 10:07 PM |
How do you set-up Outlook 2003 without the duplicate Personal Fold | Sue | Outlook - Installation | 3 | May 1st 06 12:11 AM |