Copy a large number of MailItem

N

NotAMail

Hi,

I try to copy more than 250 mailitem from my inbox folder to other folder,
"Toto" for example.
When my code attempt to copy the 244 mailitem, it raise an error.
I saw that there is a limit of item opened, which is about 255 but in
reality about 244.

The problem occurs only on Outlook 2003. Not on Outlook 200 and XP(2002).

Can somebody help me.

NotAMail

My code (extract from VB application):

Dim olApp As Outlook.Application
Dim objName As NameSpace
Sub Main()
Dim Folder As MAPIFolder, Folder2 As MAPIFolder
Dim objMailItem As Outlook.MailItem
Dim Item As Outlook.MailItem, objTemp As MailItem, objTemp2 As MailItem
Dim i As Long

Set olApp = Outlook.Application
Set objName = olApp.GetNamespace("MAPI")
Set Folder = objName.GetDefaultFolder(olFolderInbox)
Set Folder2 =
objName.GetDefaultFolder(olFolderInbox).Parent.Folders("Toto")

iCount = Folder.Items.Count
For i = 1 To iCount
Set objMailItem = Folder.Items(i)

Set objTemp = objMailItem.Copy
'Set objTemp2 = objTemp.Move(Folder2)

objTemp.Close olDiscard
'objMailItem.Close olDiscard

'Set objTemp2 = Nothing
Set objTemp = Nothing
Set objMailItem = Nothing
Next i

Set objName = Nothing
Set olApp = Nothing
End Sub
 
M

Michael Bauer

Am Thu, 18 Aug 2005 14:02:42 +0200 schrieb NotAMail:

Hi,

please try this:

Dim obj as Object

For Each obj in Folder
If TypeOf obj is Outlook.MailItem Then
Set objMailItem=obj
Set objTemp=objMailItem.Copy
Set objTemp=objTemp.Move Folder2
Set objTemp=Nothing
Set objMailItem=Nothing
Endif
Next
 
M

Michael Bauer

Am Mon, 22 Aug 2005 15:00:59 +0200 schrieb NotAMail:

You could use CDO instead of the Outlook object modell, which hasn´t a
memory leak. Maybe you need to install CDO first because it´s an
optional component (available on your Office CD).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top