I am attempting to cycle through the selected items in a displayed (Exchange) folder in the Outlook Explorer, and extract pieces of information from the e-mail messages there.
Based on code I found on this site, I have reproduced the problem as simply as possible. The code I'm using is listed below.
The problem I'm encountering is on the debug.print line, after VBA cycles through about 247 messages, it errors with the message,
However, if that same debug.print line uses the data element ".subject" instead of ".SenderName", the code works fine, and can cycle through a thousand or more messages.
I've read there may be a need to do some clean-up of objects, but I cannot quite understand exactly where or how I would do this. I'm setting "obj=nothing" after getting the information I need for each pass through the For/Next loop, but this does not resolve the problem. I've found articles describing the possibility of doing a garbage collection, or using a Marshal command, but these result in a syntax error, perhaps because I don't have the right references set in my VBA project?
I would be very grateful for any assistance or guidance in this matter.
Based on code I found on this site, I have reproduced the problem as simply as possible. The code I'm using is listed below.
The problem I'm encountering is on the debug.print line, after VBA cycles through about 247 messages, it errors with the message,
Code:
Microsoft Visual Basic
Run-time error '-2147220731 (80040305)':
Your server administrator has limited the number of items you can open simultaneously. Try closing messages you have opened or removing attachments and images from unsent messages
However, if that same debug.print line uses the data element ".subject" instead of ".SenderName", the code works fine, and can cycle through a thousand or more messages.
I've read there may be a need to do some clean-up of objects, but I cannot quite understand exactly where or how I would do this. I'm setting "obj=nothing" after getting the information I need for each pass through the For/Next loop, but this does not resolve the problem. I've found articles describing the possibility of doing a garbage collection, or using a Marshal command, but these result in a syntax error, perhaps because I don't have the right references set in my VBA project?
I would be very grateful for any assistance or guidance in this matter.
Code:
Option Explicit
Public Sub ReproduceErr()
Dim currentExplorer As Explorer
Dim obj As Object
Dim Selection As Selection
Dim Session As Outlook.NameSpace
Set currentExplorer = Application.ActiveExplorer
Set Selection = currentExplorer.Selection
For Each obj In Selection
With obj
Debug.Print .SenderName 'This caused the too many items failure when more than 250 items are selected
End With
Set obj = Nothing
Next
MsgBox "Complete"
'Clean up objects
Set Session = Nothing
Set currentExplorer = Nothing
Set obj = Nothing
Set Selection = Nothing
End Sub