tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,935
- Office Version
- 365
- 2019
- Platform
- Windows
This is the standard code for Excel to set up an e-mail in Outlook:
It works as expected.
The problem is I have to do this a number of times, eg:
When N is large, (say 50), the code crashes on this line:
with the message:
Does anyone know what is causing it and how can it be resolved?
Thanks
Code:
' early binding
Dim o As Outlook.Application
Dim om As Outlook.MailItem
Set o = New Outlook.Application
Set om = o.CreateItem(olMailItem)
With om
.BodyFormat = olFormatPlain
.Body = "hi"
.Display
.To = "dummy@dummy.com"
.Subject = "Some subject"
End With
It works as expected.
The problem is I have to do this a number of times, eg:
Code:
Const N As Long = 10
Dim o As Outlook.Application
Dim oe As Outlook.MailItem
Dim i As Long
For i = 1 to N
Set o = New Outlook.Application
Set oe = o.CreateItem(olMailItem)
With oe
.BodyFormat = olFormatPlain
.Body = "hi"
.Display
.To = "dummy@dummy.com"
.Subject = "Some subject"
End With
Next i
When N is large, (say 50), the code crashes on this line:
Code:
.Display
with the message:
Code:
[ATTACH type="full" size="329x194"]120684[/ATTACH]
Does anyone know what is causing it and how can it be resolved?
Thanks