run time error when sending mail from vba

stevebrodie

New Member
Joined
Jan 11, 2011
Messages
17
Hi All,

If this has been answered apologies, but i cannot find the exact answer. I have set up an email list for distribution of an excel workbook, but no matter what i try i always get an error 'Run-time error 1004' Method 'sendmail' of object'_workbook' Failed

Code:
[FONT=Arial]Sub mail()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>[/FONT]
[FONT=Arial]Dim cell As Range<o:p></o:p>[/FONT]
[FONT=Arial]Dim strto As String<o:p></o:p>[/FONT]
[FONT=Arial]For Each cell In ThisWorkbook.Sheets("DropDownData").Columns("H").Cells.SpecialCells(xlCellTypeConstants)<o:p></o:p>[/FONT]
[FONT=Arial]If cell.Value Like "*@*" Then<o:p></o:p>[/FONT]
[FONT=Arial]strto = strto & cell.Value & ";"<o:p></o:p>[/FONT]
[FONT=Arial]End If<o:p></o:p>[/FONT]
[FONT=Arial]Next<o:p></o:p>[/FONT]
[FONT=Arial]'ActiveWorkbook.SaveAs "Morning Report for a" & Format(Date, "dd mmm")<o:p></o:p>[/FONT]
[FONT=Arial]ActiveWorkbook.SendMail Recipients:=strto<o:p></o:p>[/FONT]

Starting to pull my hair out, what little i have left :laugh:
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try something like this...

Code:
Sub mail()
    Dim cell   As Range
    Dim vTo  As Variant
    For Each cell In ThisWorkbook.Sheets("DropDownData").Columns("H").Cells.SpecialCells(xlCellTypeConstants)
        If cell.Value Like "*@*" Then
            vTo = vTo & cell.Value & ";"
        End If
    Next
    vTo = Split(Left(vTo, Len(vTo) - 1), ";")
    'ActiveWorkbook.SaveAs "Morning Report for a" & Format(Date, "dd mmm")
    ActiveWorkbook.SendMail Recipients:=vTo
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,862
Members
452,948
Latest member
UsmanAli786

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