VBA code to create an email not importing names in "To, CC, or BCC"

jmk15315

Board Regular
Joined
Nov 7, 2021
Messages
71
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
Good morning.

I have a VBA code that works. By that, I mean that it opens Outlook to create a message and populates some of the information, but does not pull the recipients from the list in my worksheet.
I was hoping someone could help point me toward what I am doing wrong, or where the problem might reside.

This is the code I have.

VBA Code:
Private Sub CommandButton150_Click()
   
' EMAIL ROBOT FORCAST TO ABB REP

    Dim OutApp As Object
    Dim OutMail As Object
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    On Error Resume Next
   
        With OutMail
            .To = Sheet26.Range("ER6:ER18")
            .CC = Sheet26.Range("ER19:ER24")
            .BCC = Sheet26.Range("ER26:ER28")
            .Recipients.ResolveAll
            .Subject = "ROBOT FORCAST (COBOT SYSTEM)" & "REFERENCE" & "-" & Sheets("SUMMARY").Range("B5")
            .Body = "Attached is a pdf copy of the Robot Forcasting sheet."
            .Attachments.Add
            .Display
        End With
        On Error GoTo 0
    
' INDICATE EMAIL SENT 
 MsgBox "File sent successfully"
        
        Set OutMail = Nothing
        Set OutApp = Nothing

End Sub

Any thoughts would be helpful
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
What happens when you do this ?

VBA Code:
            .To = Join(Application.Transpose(Sheet26.Range("ER6:ER18")), ";")
            .cc = Join(Application.Transpose(Sheet26.Range("ER19:ER24")), ";")
            .bcc = Join(Application.Transpose(Sheet26.Range("ER26:ER28")), ";")
 
Upvote 1

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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