Runtime Error -2147221238(8004010a)

stuartgb100

Active Member
Joined
May 10, 2015
Messages
287
Office Version
  1. 2021
Platform
  1. Windows
Hi,

The error message goes on to say
"The item has been moved or deleted".

This is occurring during a batch email routine, where the email
addresses are held as strings in an array.

The routine works find until the second run through, when it fails
on the line
.To

And yet there is clearly a value (valid email address) as the 2nd
element of the array.

Can anyone help, please ?
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
I know this post is a little long in the tooth, but I am having the identical issue as described here -

Does anyone have any ideas - code below works great for the first run but on run # 2 - I get the above error

Code:
Dim OutlookApp As Object
Dim OutlookMailItem As Object
Dim MyAttachments As Object
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMailItem = OutlookApp.CreateItem(0)
Set MyAttachments = OutlookMailItem.Attachments

With OutlookMailItem
      .To = "[EMAIL="Mike.M.Smith@MSN.COM"]Mike.M.Smith@MSN.COM[/EMAIL]"
        .Subject = "Test"
          .Body = "Boo"
        MyAttachments.Add "N:\Management\Internal\Common\Sales Current Reports\SalesRpts_North\2018_DailySalesReport_" & Format(Rng2, "M-D-YYYY") & ".xls"
      .Send
    End With
 
Upvote 0
Can't give up on this - 370+ views and no hint of a solution - Well, this is what I've done up to this point and it appears to be working with consistency... but I'm not an expert so I can't explain it perhaps someone here can...

What I did was simply re-Set the Outlook Objects in front of the second Email Send.
Thus, I just put the same three 'Set' lines below of code in front of the second pass and thus far, no more 2147221238 Error

But why?

Code:
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
Set Attachments = OutlookMail.Attachments

Thanks
 
Upvote 0
Was your original code in some sort of loop, or were you rerunning the whole thing?
 
Upvote 0
You must Set the objects every time you create a new email. It means that if you're in a loop, this must go INSIDE the loop and not before.

This is what happened to me.

VBA Code:
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
Set Attachments = OutlookMail.Attachments
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

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