Message Item MOVE

  • Thread starter Thread starter Slava
  • Start date Start date
S

Slava

Hi,
Im trying to move message from incoming folder to the specific folder,
but without effect :o((

objInboxItems_ItemAdd(ByVal Item As Object)
Dim NS As NameSpace
Dim myInbox As MAPIFolder
Dim desFld As Outlook.MAPIFolder

Set NS = Application.Session
Set myInbox = NS.GetDefaultFolder(olFolderInbox)
Set desFld = myInbox.Folders("ABCD")
Item.Move desFld


but nothing is done :o((
/when I set a MsgBox - the message is displayed./


what is wrong ?

sincerely
slava
 
I haven't been able to find a batch MOVE command. I'm really new at VBA but have had a lot of programming experience. Here's how I would have done it using a while...wend loop to move each item from the inbox to the destination folder

Sub test(

Dim myInbox As Outlook.MAPIFolder, desFld As Outlook.MAPIFolde
Dim myItems As Outlook.MailItem
Dim NumberofMessages As Intege

Set myInbox = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox
Set desFld = GetNamespace("MAPI").Folders("desFld"

NumberofMessages = myInbox.Items.Coun

While NumberofMessages >

Set myItems = myInbox.Items.Item(NumberofMessages
myItems.Move desFl

NumberofMessages = myInbox.Items.Count 'since the number of messages changes each time one moves this must be updated each iteratio

Wen

End Su

Repost if this isn't what you were looking for

Kenneth Rom
LT, US
 
How would this be done if desFld is not in the default information store,
but in an additional mailbox in the user's profile?
 
Other loaded .pst's are top level folders in the NameSpace.Folders
collection. This handy class can parse all folders in all stores, and
should give you a good overview of the relationship between Folders and
Stores:

Option Explicit
Dim I As Integer
Dim arrPath() As String
Dim myApp As Outlook.Application
Dim myNs As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim colFolders As Folders
Dim colFolders2 As Folders

Sub Run()
Set myApp = New Outlook.Application
Set myNs = myApp.GetNamespace("MAPI")
Set colFolders = myNs.Folders
RecurseMailFolders colFolders
End Sub

Sub RecurseFolders(objTheseFolders As Outlook.Folders)
For Each myFolder In objTheseFolders
' Debug.Print myFolder.Name
ReDim Preserve arrPath(I + 1)
arrPath(I) = myFolder.FolderPath
Set colFolders2 = myFolder.Folders
I = I + 1
RecurseFolders colFolders2
Next
End Sub

Sub RecurseMailFolders(objTheseFolders As Outlook.Folders)
Dim lngItemCount As Long
For Each myFolder In objTheseFolders
' Debug.Print myFolder.Name
If myFolder.DefaultItemType = olMailItem Then
ReDim Preserve arrPath(I + 1)
arrPath(I) = myFolder.FolderPath
lngItemCount = myFolder.Items.Count
Set colFolders2 = myFolder.Folders
I = I + 1
RecurseMailFolders colFolders2
End If
Next
End Sub
 
Thanks - this was a big help!

Eric Legault said:
Other loaded .pst's are top level folders in the NameSpace.Folders
collection. This handy class can parse all folders in all stores, and
should give you a good overview of the relationship between Folders and
Stores:

Option Explicit
Dim I As Integer
Dim arrPath() As String
Dim myApp As Outlook.Application
Dim myNs As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim colFolders As Folders
Dim colFolders2 As Folders

Sub Run()
Set myApp = New Outlook.Application
Set myNs = myApp.GetNamespace("MAPI")
Set colFolders = myNs.Folders
RecurseMailFolders colFolders
End Sub

Sub RecurseFolders(objTheseFolders As Outlook.Folders)
For Each myFolder In objTheseFolders
' Debug.Print myFolder.Name
ReDim Preserve arrPath(I + 1)
arrPath(I) = myFolder.FolderPath
Set colFolders2 = myFolder.Folders
I = I + 1
RecurseFolders colFolders2
Next
End Sub

Sub RecurseMailFolders(objTheseFolders As Outlook.Folders)
Dim lngItemCount As Long
For Each myFolder In objTheseFolders
' Debug.Print myFolder.Name
If myFolder.DefaultItemType = olMailItem Then
ReDim Preserve arrPath(I + 1)
arrPath(I) = myFolder.FolderPath
lngItemCount = myFolder.Items.Count
Set colFolders2 = myFolder.Folders
I = I + 1
RecurseMailFolders colFolders2
End If
Next
End Sub
 
Back
Top