Email with .Body & .To using Variable for the .To

tcnt9176

Board Regular
Joined
Jun 23, 2008
Messages
223
I have an email challenge that I have not been able to overcome. I was using Sendmail but could not add anything to the body of the email. I switched over to the method below but have not been able to figure out how to use a variable in the .To instead of an email address. The email addresses will change everytime this macro is used so that is the reason it needs to be a variable and not just an email group. Thanks for your help!!

Code:
    Dim vAddresses As Variant
    With ActiveSheet
        vAddresses = Application.Transpose(.Range("C2:C" & _
            .Cells(Rows.Count, "C").End(xlUp).Row))
    End With

   Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
        If ActiveWorkbook.Path <> "" Then
            Set OutApp = CreateObject("Outlook.Application")
            Set OutMail = OutApp.CreateItem(0)

            
strbody = "[SIZE=3]" & _
"All,
" & _
"Testing.
[B]"
                      
    
            On Error Resume Next
            With OutMail
                .To = vAddresses
                .CC = 
                .BCC = ""
                .Subject = "Claim Number Validation Report- " & Format(Date, "mm/dd/yy")
                .HTMLBody = strbody
                .Attachments.Add ("[URL="file://\\abc\client_services$\1"]\\abc\[/URL]ABC Report " & Format(Date, "yyyy.mm.dd") & ".xls")
                .Display
                .Send
            End With
            On Error GoTo 0
    
            Set OutMail = Nothing
            Set OutApp = Nothing
        Else
            MsgBox "The ActiveWorkbook does not have a path, Save the file first."
        End If
[/B][/SIZE]
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
daverunt....You are AWESOME!!

Just so it is here for reference for anyone else that needs this, I just added the Join function to add commas and it worked fine.

Code:
vAddresses = Application.Transpose(.Range("C2:C" & _
            .Cells(Rows.Count, "C").End(xlUp).Row))       

vAddresses = Join(Application.Transpose(.Range("C2:C" & _
            .Cells(Rows.Count, "C").End(xlUp).Row)), ", ")
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,448
Members
448,966
Latest member
DannyC96

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