![]() |
| 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. |
|
|||||||
| Tags: code, current, folder, message, move, using, vba |
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Hello,
I want to automate the task of moving the currently open Outlook message into a folder called "TEMP" I found a code example on this forum but have a few questions. My variation of the code pasted below. 1) How do I dimension those object variables (note ????? in the code)? 2) Does the code look right? Thanks in advance for any help you can provide. Best Regards, Dean '--------------------------------------------------------------------------- Public Sub moveMsgToTEMP() On Error GoTo Err_moveMsgToTEMP 'this sub moves the currently open message to the TEMP folder Dim objApp As Outlook.Application Dim olnBoxItems as ????? Dim olNS As Outlook.NameSpace 'Dim objTargetFolder as ??????? Dim colFolders As Outlook.Folders Dim objFolder As Outlook.MAPIFolder Dim objCurItem as ?????? Set oInBoxItems = objNS.GetDefaultFolder(olFolderInbox).Items Set olNS = Item.Application.GetNamespace("MAPI") Set objTargetFolder = objInbox.Folders("TEMP") Set objCurItem = objCurItem.Move(objTargetFolder) objCurItem.Save Exit_moveMsgToTEMP: Exit Sub Err_moveMsgToTEMP: MsgBox "sub moveMsgToTEMP " & Err.Description Resume Exit_moveMsgToTEMP End Sub '--------------------------------------------------------------------------- |
| Ads |
|
#2
|
|||
|
|||
|
Am Sat, 25 Feb 2006 08:24:56 GMT schrieb Dean:
Very good Dean, just a little messed up :-) You need a ref onto the currently opened item. If you want to handle every item types with then you can use a declaration As Object. Else, if there are MailItems only you could declare the variable As MailItem. Then you need a ref onto the target folder. Every folder is the same object type of and is called MapiFolder. If the target folder is a subfolder of the Inbox then get a ref onto the Inbox (itself, not its Items) first then onto a child of it. In code: Dim objCurItem as Object Dim InboxFolder as Outlook.MapiFolder Dim TargetFolder as Outlook.MapiFolder ' currently opened item Set objCurItem = Application.ActiveInspector.CurrentItem ' Inbox folder Set InboxFolder = Application.Session.GetDefaultFolder(olInboxFolder ) ' Subfolder of the Inbox Set TargetFolder = InboxFolder.Item("TEMP") ' Move the message Set objCurItem = objCurItem.Move(TargetFolder) -- Viele Gruesse / Best regards Michael Bauer - MVP Outlook -- www.vbOffice.net -- Hello, I want to automate the task of moving the currently open Outlook message into a folder called "TEMP" I found a code example on this forum but have a few questions. My variation of the code pasted below. 1) How do I dimension those object variables (note ????? in the code)? 2) Does the code look right? Thanks in advance for any help you can provide. Best Regards, Dean '--------------------------------------------------------------------------- Public Sub moveMsgToTEMP() On Error GoTo Err_moveMsgToTEMP 'this sub moves the currently open message to the TEMP folder Dim objApp As Outlook.Application Dim olnBoxItems as ????? Dim olNS As Outlook.NameSpace 'Dim objTargetFolder as ??????? Dim colFolders As Outlook.Folders Dim objFolder As Outlook.MAPIFolder Dim objCurItem as ?????? Set oInBoxItems = objNS.GetDefaultFolder(olFolderInbox).Items Set olNS = Item.Application.GetNamespace("MAPI") Set objTargetFolder = objInbox.Folders("TEMP") Set objCurItem = objCurItem.Move(objTargetFolder) objCurItem.Save Exit_moveMsgToTEMP: Exit Sub Err_moveMsgToTEMP: MsgBox "sub moveMsgToTEMP " & Err.Description Resume Exit_moveMsgToTEMP End Sub '--------------------------------------------------------------------------- |
|
#3
|
|||
|
|||
|
Hi Michael,
Thanks for the advice. I'm still having a problem with this line: Set InboxFolder = Application.Session.GetDefaultFolder(olInboxFolder ) I thought maybe it was a problem with "olInboxFolder" and tried the constant "olFolderInbox" but that didn't work. I'm also wondering if I need the lack of NameSpace and BoxItems instantiations is a problem. Thanks. Michael Bauer wrote: Am Sat, 25 Feb 2006 08:24:56 GMT schrieb Dean: Very good Dean, just a little messed up :-) You need a ref onto the currently opened item. If you want to handle every item types with then you can use a declaration As Object. Else, if there are MailItems only you could declare the variable As MailItem. Then you need a ref onto the target folder. Every folder is the same object type of and is called MapiFolder. If the target folder is a subfolder of the Inbox then get a ref onto the Inbox (itself, not its Items) first then onto a child of it. In code: Dim objCurItem as Object Dim InboxFolder as Outlook.MapiFolder Dim TargetFolder as Outlook.MapiFolder ' currently opened item Set objCurItem = Application.ActiveInspector.CurrentItem ' Inbox folder Set InboxFolder = Application.Session.GetDefaultFolder(olInboxFolder ) ' Subfolder of the Inbox Set TargetFolder = InboxFolder.Item("TEMP") ' Move the message Set objCurItem = objCurItem.Move(TargetFolder) Hello, I want to automate the task of moving the currently open Outlook message into [quoted text clipped - 7 lines] Best Regards, Dean '--------------------------------------------------------------------------- Public Sub moveMsgToTEMP() On Error GoTo Err_moveMsgToTEMP [quoted text clipped - 21 lines] Resume Exit_moveMsgToTEMP End Sub '--------------------------------------------------------------------------- |
|
#4
|
|||
|
|||
|
Am Sat, 25 Feb 2006 11:31:37 GMT schrieb Dean:
Sorry, olFolderInbox is correct. What do you mean by "that doesn´t work", do you get an error? -- Viele Gruesse / Best regards Michael Bauer - MVP Outlook -- www.vbOffice.net -- Hi Michael, Thanks for the advice. I'm still having a problem with this line: Set InboxFolder = Application.Session.GetDefaultFolder(olInboxFolder ) I thought maybe it was a problem with "olInboxFolder" and tried the constant "olFolderInbox" but that didn't work. I'm also wondering if I need the lack of NameSpace and BoxItems instantiations is a problem. Thanks. Michael Bauer wrote: Am Sat, 25 Feb 2006 08:24:56 GMT schrieb Dean: Very good Dean, just a little messed up :-) You need a ref onto the currently opened item. If you want to handle every item types with then you can use a declaration As Object. Else, if there are MailItems only you could declare the variable As MailItem. Then you need a ref onto the target folder. Every folder is the same object type of and is called MapiFolder. If the target folder is a subfolder of the Inbox then get a ref onto the Inbox (itself, not its Items) first then onto a child of it. In code: Dim objCurItem as Object Dim InboxFolder as Outlook.MapiFolder Dim TargetFolder as Outlook.MapiFolder ' currently opened item Set objCurItem = Application.ActiveInspector.CurrentItem ' Inbox folder Set InboxFolder = Application.Session.GetDefaultFolder(olInboxFolder ) ' Subfolder of the Inbox Set TargetFolder = InboxFolder.Item("TEMP") ' Move the message Set objCurItem = objCurItem.Move(TargetFolder) Hello, I want to automate the task of moving the currently open Outlook message into [quoted text clipped - 7 lines] Best Regards, Dean '--------------------------------------------------------------------------- Public Sub moveMsgToTEMP() On Error GoTo Err_moveMsgToTEMP [quoted text clipped - 21 lines] Resume Exit_moveMsgToTEMP End Sub '--------------------------------------------------------------------------- |
|
#5
|
|||
|
|||
|
Hi Michael,
I was getting an error (forget the exact error message). I combined the advice you gave me along with some code I pulled off of the MS website and came up with something that works (pasted below). Thanks for your help! Best Regards, Dean '----------------------------------------------------------------------------- ------------- Public Sub moveMsgToTEMP() On Error GoTo Err_moveMsgToTEMP 'this sub moves the currently open message to the TEMP folder Dim myOlApp As New Outlook.Application Dim myNameSpace As Outlook.NameSpace Dim myInbox As Outlook.MAPIFolder Dim myDestFolder As Outlook.MAPIFolder Dim myItems As Outlook.Items Dim myItem As Object Set myNameSpace = myOlApp.GetNamespace("MAPI") Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox) Set myItems = myInbox.Items Set myDestFolder = myInbox.Folders("TEMP") Set myItem = Application.ActiveInspector.CurrentItem myItem.Move myDestFolder Exit_moveMsgToTEMP: Exit Sub Err_moveMsgToTEMP: MsgBox "sub moveMsgToTEMP " & Err.Description Resume Exit_moveMsgToTEMP End Sub '--------------------------------------------------------------------- Michael Bauer wrote: Am Sat, 25 Feb 2006 11:31:37 GMT schrieb Dean: Sorry, olFolderInbox is correct. What do you mean by "that doesn´t work", do you get an error? Hi Michael, Thanks for the advice. I'm still having a problem with this line: [quoted text clipped - 51 lines] '--------------------------------------------------------------------------- -- Message posted via http://www.officekb.com |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| VBA Code to put in Access that will send an Email with Attachments | jon.ingram@comcast.net | Outlook and VBA | 1 | April 9th 06 05:30 PM |
| how to apply vba code to OL2003 forms ? | TimR | Outlook - Using Contacts | 1 | February 17th 06 04:41 PM |
| Outlook Message Count - VBA Error - Multiple Inboxes | Ryan | Outlook and VBA | 3 | February 15th 06 10:35 PM |
| VBA Code to check Task Status | techiemom@gmail.com | Outlook and VBA | 2 | February 3rd 06 06:16 PM |
| Running query from Access Form commmand using VBA code | Berny | Outlook and VBA | 4 | January 16th 06 02:12 PM |