S
snaux
I've written an Outlook 2003 VBA script which creates multiple emails
in the drafts box. I'd like to send them all, but at the 100th "send"
command the system chokes, and the emails get moved or deleted, but are
not actually sent out.
Here's my code:
Sub SendMerge()
Dim oItem As MailItem
Dim olfldrSource As MAPIFolder
Dim nSendCount As Integer
nSendCount = 1
doneScan = False
While (doneScan = False)
Set olfldrSource =
Outlook.GetNamespace("MAPI").GetDefaultFolder(olFolderDrafts)
If (olfldrSource.Items.count() = 0) Then
doneScan = True
End If
Set oItem = olfldrSource.Items(1)
DoEvents
Debug.Print nSendCount & " Sending: " & oItem.To & " Email:
" & oItem.Subject
nSendCount = nSendCount + 1
oItem.Send
Set oItem = Nothing
Set olfldrSource = Nothing
Wend
End Sub
I know similar problems have been discussed before, but I've not seen a
conclusive answer. After reading the boards, I believe the problem is
that I've exceeded the number of COM objects allowed by the Exchange
Server, but this is just a guess.
I've also seen posts about explicit Garbage Collection above and beyond
setting all Objects = Nothing, but I've seen no examples on how to do
this.
Does anyone have any suggestions? What am I doing wrong and how do I
fix this?
in the drafts box. I'd like to send them all, but at the 100th "send"
command the system chokes, and the emails get moved or deleted, but are
not actually sent out.
Here's my code:
Sub SendMerge()
Dim oItem As MailItem
Dim olfldrSource As MAPIFolder
Dim nSendCount As Integer
nSendCount = 1
doneScan = False
While (doneScan = False)
Set olfldrSource =
Outlook.GetNamespace("MAPI").GetDefaultFolder(olFolderDrafts)
If (olfldrSource.Items.count() = 0) Then
doneScan = True
End If
Set oItem = olfldrSource.Items(1)
DoEvents
Debug.Print nSendCount & " Sending: " & oItem.To & " Email:
" & oItem.Subject
nSendCount = nSendCount + 1
oItem.Send
Set oItem = Nothing
Set olfldrSource = Nothing
Wend
End Sub
I know similar problems have been discussed before, but I've not seen a
conclusive answer. After reading the boards, I believe the problem is
that I've exceeded the number of COM objects allowed by the Exchange
Server, but this is just a guess.
I've also seen posts about explicit Garbage Collection above and beyond
setting all Objects = Nothing, but I've seen no examples on how to do
this.
Does anyone have any suggestions? What am I doing wrong and how do I
fix this?