Help with EMAIL macro

antonschoene

New Member
Joined
Jul 1, 2014
Messages
2
Hello everyone, I am new to the forum and am really stuck with this macro. I have searched and found multiple macros regarding emails and have had them work with one exception. The range that i am pulling the emails from has blanks. The list starts in cell BD9 and goes until BD45. The macro below works great if there is no blanks, but do to people coming and going from my list i will always have blanks. The macro gets hung up with the following [If cell.Value Like "?*@?*.?*" Then] line. Is there anything i can add the the code to ignore the blanks and go on to the next cell???

Dim cell As Range
Dim strto As String
For Each cell In ThisWorkbook.Sheets("Contacts").Range("BD9:BD45")
If cell.Value Like "?*@?*.?*" Then
strto = strto & cell.Value & ";"
End If
Next cell
If Len(strto) > 0 Then strto = Left(strto, Len(strto) - 1)
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
On Error GoTo cleanup
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = strto
.Subject = Worksheets("Contacts").Range("ac18")
.Body = ""
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi,

I don't see an error when using the 'like' part of the code even when the cell is blank.
However you would possibly have problems in the address list with empty cells.

Code:
For Each cell In ThisWorkbook.Sheets("Contacts").Range("BD9:BD45")
 If cell.Value Like "?*@?*.?*" Then
 If cell.Value <> "" Then

 strto = strto & cell.Value & ";"
 End If
 End If
 Next cell
 
Last edited:
Upvote 0
You could of course clean out the blanks from the mailing list before running the e-mail macro.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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