I can't get my attachments to work when emailing from excel

Alphaboss7

New Member
Joined
Jul 31, 2017
Messages
28
This line of code is not running:

Code:
.Attachments.Add Range("I" & i).Value

within this code:

Code:
Sub CreateMail()
    Dim objOutlook      As Object
    Dim objMail         As Object
    Dim i               As Integer
    Const olMailItem    As Long = 0
    Dim strbody As String
    
    For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row '~~> Change to i = 2 if you have headings
        Set objOutlook = CreateObject("Outlook.Application")
        Set objMail = objOutlook.CreateItem(olMailItem)
        
        strbody = Range("K2") & " " & Range("A" & i) & "
" & "
" & _
                Range("K3") & "
" & "
" & _
                Range("K4") & " " & Range("B" & i).Value & "
" & _
                Range("K5") & " " & Range("C" & i).Value & "
" & _
                Range("K6") & " " & Range("K7") & "
" & "
" & _
                Range("K8") & "
" & "
" & _
                Range("K9") & "
" & "
" & _
                Range("K10")
                                        
        With objMail '~~> Chnage Below columns to suit your data, this was based off your example offsets
            .To = Range("F" & i).Value
            .cc = Range("G" & i).Value
            .Subject = Range("J" & i).Value
            .Attachments.Add Range("I" & i).Value                                   '<-----This is the line that won't work
            .HTMLBody = strbody '~~> You can change this to any range
            
            .display
        End With
                                        
        Set objOutlook = Nothing
        Set objMail = Nothing
    Next i
End Sub

Any suggestions?
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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