lukeskiiwalker
New Member
- Joined
- Jun 8, 2023
- Messages
- 4
- Office Version
- 365
- Platform
- Windows
Hello everyone,
Any help would be much appreciated. I'm trying to create a command button that will send emails from a certain range, say F2:F175. I would like this code to remove any duplicate emails in that range and not count any blank or 0 cells. Is this possible? below is what I have already started.
Thanks for any advice you can give me,
Rob
Private Sub CommandButton1_Click()
On Error GoTo ErrHandler
Dim objOutlook As Object
Set objOutlook = CreateObject("Outlook.Application")
Dim objEmail As Object
Set objEmail = objOutlook.CreateItem(olMailItem)
Dim myDataRng As Range
Set myDataRng = Range("f2:f175" & Cells(Rows.Count, "A").End(xlUp).Row)
Dim cell As Range
Dim iCnt As Integer
Dim sMail_ids As String
For Each cell In myDataRng
If Trim(sMail_ids) = "" Then
sMail_ids = cell.Offset(1, 0).Value
Else
sMail_ids = sMail_ids & vbCrLf & ";" & cell.Offset(1, 0).Value
End If
Next cell
Set myDataRng = Nothing
With objEmail
.To = sMail_ids
.Body = "Hello,"
.Display
End With
Set objEmail = Nothing: Set objOutlook = Nothing
ErrHandler:
'
End Sub
Any help would be much appreciated. I'm trying to create a command button that will send emails from a certain range, say F2:F175. I would like this code to remove any duplicate emails in that range and not count any blank or 0 cells. Is this possible? below is what I have already started.
Thanks for any advice you can give me,
Rob
Private Sub CommandButton1_Click()
On Error GoTo ErrHandler
Dim objOutlook As Object
Set objOutlook = CreateObject("Outlook.Application")
Dim objEmail As Object
Set objEmail = objOutlook.CreateItem(olMailItem)
Dim myDataRng As Range
Set myDataRng = Range("f2:f175" & Cells(Rows.Count, "A").End(xlUp).Row)
Dim cell As Range
Dim iCnt As Integer
Dim sMail_ids As String
For Each cell In myDataRng
If Trim(sMail_ids) = "" Then
sMail_ids = cell.Offset(1, 0).Value
Else
sMail_ids = sMail_ids & vbCrLf & ";" & cell.Offset(1, 0).Value
End If
Next cell
Set myDataRng = Nothing
With objEmail
.To = sMail_ids
.Body = "Hello,"
.Display
End With
Set objEmail = Nothing: Set objOutlook = Nothing
ErrHandler:
'
End Sub