Hi all,
I think this is all fairly standard. New job, never coded in VBA. One of my first assignments was 'to make something to save all those attachments easier'. I believe this is almost 'the' standard problem when people enroll into VBA.
However, I have been banging my head against the wall because I'm receiving the following error when the # of messages becomes >>200.
Your server administrator has limited the number of items you can open simoultaneously. Try closing messages you have opened or removing attachments and images from unsent messages you are composing.
So, I tried various things:
- Enable explicit mode
- Declare variables outside the each loop
- Link the loop object to another object and then destroy the later object
Nothing appears to work. Below will demonstrate my problem. I distilled this small macro from my (by now) huge project (people tend to see more issue's when you solve the first one ... amazing!).
The macro will simply fill two string variables based on each mail selected. Eventually the script will end because of the limit. If I select # 500 messages, the amount of loops ran by this macro will never exceed 250. It will only exceed this number when I include mails that have no attachments.
Could anyone *please* shed some light on this? I'm at a loss here.
Environment:
Windows Server 2008
Microsoft Outlook 2010
Microsoft Exchange 2010 (I think ...)
Option Explicit
Sub Main()
Dim SELObject As Variant
Dim usr_name As String
Dim usr_counter As String
Dim index As Integer
index = 0
For Each SELObject In ActiveExplorer.Selection
If TypeName(SELObject) = "MailItem" Then
On Error GoTo EndSub
'the assumption of at least one attachment is safely satisfied
usr_name = SELObject.Attachments.Item(1).FileName
usr_counter = SELObject.Attachments.Count
On Error GoTo 0
SELObject.Close olSave
End If
index = index + 1
usr_counter = ""
usr_name = ""
Set SELObject = Nothing
Next
EndSub:
MsgBox index
End Sub