...administrator has limited the number of items you can open simultaneously

Status
Not open for further replies.

Blair

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Exchange Server
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,

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
 

Blair

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Exchange Server
Michael,

Thanks. That is helpful, although that code operates on all items within a specified folder. I'll have to play with it to get it to function for selected messages.

Time for a refresher on Outlook's object model.

-Blair
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Look at the code, instead of looping through Items, you'd loop through Selection.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Yeah, using cached mode resolves a lot of issues...
 
Status
Not open for further replies.
Top