Excel to Outlook error

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,935
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
This is the standard code for Excel to set up an e-mail in Outlook:

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
 

Attachments

  • 1735319718458.png
    1735319718458.png
    27 KB · Views: 6
I suspect you may be right (and suggested as much). As such, I don't think there is much more that I can give you, from an Excel standpoint.

As for the randomness of the number, it could be dependent upon what else may be happening on your computer at the same time, using it resources.
Or how much memory Outlook may be using at the moment.

Like I said, short of changing your approach, the only recommendation I can make to you if you want to use your current methodology is to limit the number of emails is does at a time so you don't run into that error.
I really have no other suggestions for you.

I did find this article, which seems to talk about the problem you are experiencing, and their recommendations:
Classic Outlook errors opening more than sixty emails at the same time - Microsoft Support.
Thanks for taking the time to investigate and the link.
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,225,346
Messages
6,184,400
Members
453,230
Latest member
ProdInventory

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top