Hi Forum
2007 / XP
I have a process which brings emails into a table in Excel (TimeReceived, Sender, Subject, Body, Mail Folder). I have to use MAPI because it is a group mailbox, which cannot be controlled with standard outlook vba like a primary outlook folder.
When the macro runs through a folder with about 700 mails in it it takes a good 10-15 minutes to complete.
With a little diagnosis I have worked out that this is because every time I pick up the sender property of my mapiitem it takes 10-15 seconds to do so.
I have (abridged) code as follows:
My theory is that by using variants and objects and writing MapiItem.Sender directly to a cell I may be making Excel do a lot of detective work to figure out what type (string/date/object etc) each of these objects might be.
(Q1) Do any of you know how I could more accurately declare:
ALSO if I amend the code to stop the direct write to cells of an unknown object....
(Q2) What should mapiSender be declared as?
(Q3) .Cells(...).Value = mapiSender.Something <<<< What should the property in the last line of the above code be. Maybe .name?
(Q4) Am I barking up the wrong tree - is the slowdown caused by something else?
Thanks for looking!
Tom
2007 / XP
I have a process which brings emails into a table in Excel (TimeReceived, Sender, Subject, Body, Mail Folder). I have to use MAPI because it is a group mailbox, which cannot be controlled with standard outlook vba like a primary outlook folder.
When the macro runs through a folder with about 700 mails in it it takes a good 10-15 minutes to complete.
With a little diagnosis I have worked out that this is because every time I pick up the sender property of my mapiitem it takes 10-15 seconds to do so.
I have (abridged) code as follows:
Code:
Dim MapiSess As Object
Dim MapiFolderInbox As Object
Dim MapiItem As Object
Dim arrMailboxes As Variant
Set MapiSess = CreateObject("MAPI.Session")
MapiSess.Logon "Outlook"
Set MapiFolderInbox = MapiSess.InfoStores(arrMailboxes(j)).RootFolder.Folders(strFolder(i))
For Each MapiItem In MapiFolderInbox.Messages
'THIS IS THE LINE THAT TAKES A LONG TIME
.Cells(NumMails + RowHeader, ColSender).Value = MapiItem.Sender
Next MapiItem
My theory is that by using variants and objects and writing MapiItem.Sender directly to a cell I may be making Excel do a lot of detective work to figure out what type (string/date/object etc) each of these objects might be.
(Q1) Do any of you know how I could more accurately declare:
Code:
Dim MapiSess As ?
Dim MapiFolderInbox As ?
Dim MapiItem As ?
Dim arrMailboxes As ?
ALSO if I amend the code to stop the direct write to cells of an unknown object....
Code:
Dim mapiSender
Set mapiSender=MapiItem.Sender
.Cells(NumMails + RowHeader, ColSender).Value = mapiSender
(Q2) What should mapiSender be declared as?
(Q3) .Cells(...).Value = mapiSender.Something <<<< What should the property in the last line of the above code be. Maybe .name?
(Q4) Am I barking up the wrong tree - is the slowdown caused by something else?
Thanks for looking!
Tom
Last edited: