outlook mail in xl2010

diddi

Well-known Member
Joined
May 20, 2004
Messages
3,337
Office Version
  1. 2010
Platform
  1. Windows
greets all. i have come across my first difficulty using xl2010... this code based on ronDB's code has worked for me for ages, but under 2010 it falls over here:
OlMail.Recipients.Add ToRecipient

has the object model changed? i couldnt find anything at msdn.
TIA

Code:
     ' emailName is a Public string

    Dim OlApp As Object, OlMail As Object
    Dim ToRecipient As Variant

            Set OlApp = CreateObject("Outlook.Application")
            Set OlMail = OlApp.createitem(olmailitem)
            
                For Each ToRecipient In Array(emailName) 
                    OlMail.Recipients.Add ToRecipient
                Next ToRecipient
        
            OlMail.Subject = Label2.Caption & " from me"
            OlMail.body = "Please find attached invoice." & Chr(13) & "my name"
            OlMail.Attachments.Add "D:\My Invoices\" & Label2.Caption & ".pdf"

            OlMail.Send
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
What string has your variable emailName been assigned? If, for example, you have the following...

Code:
emailName = "Joe@abc.com;John@xyz.com"

...try replacing...

Code:
For Each ToRecipient In Array(emailName)

with

Code:
For Each ToRecipient In Split(emailName, ";")
 
Upvote 0
quick update...

after trying domenic's suggestion without any luck
i stumbled in the dark until...
Code:
                For Each ToRecipient In Array(emailName) 
                    OlMail.Recipients.Add ToRecipient
                Next ToRecipient

change to this
Code:
                For Each ToRecipient In Array(emailName) 
                    OlMail.To ToRecipient
                Next ToRecipient
and all is good
 
Upvote 0

Forum statistics

Threads
1,226,240
Messages
6,189,823
Members
453,573
Latest member
adefonzo23

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