Sub Mail_Outlook()
Dim receiver As String
Dim ccreceiver As String
Dim subject As String
Dim message As String
Dim OutApp As Object
Dim OutMail As Object
Dim thissheet As String
thissheet = ActiveSheet.Name ' points to the active sheet in use
Dim head As Range
Dim rng As Range
Set rng = Nothing
ccreceiver = ""
On Error Resume Next
receiver = Range("C" & CStr(ActiveCell.Row())).Value
Set rng = Selection.SpecialCells(xlCellTypeVisible)
Set head = Sheets(thissheet).Range("A2:C2").SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected" & _
vbNewLine & "please correct and try again.", vbOKOnly
Exit Sub
End If
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
' setting subject
Sheets("1. Highlevel ").Select
subject = Range("C6").Value & " - " & Range("C5").Value & " - Activities"
Sheets("4. MOBILE").Select
Range("I3").Select
Do While ActiveCell.Value <> "End"
If ActiveCell.Value = "X" Or ActiveCell.Value = "x"
If HasHyperlink(ActiveCell.Offset(0, -1)) Then
ccreceiver = ccreceiver & ";" & GetAddress(ActiveCell.Offset(0, -1))
Else
ccreceiver = ccreceiver & ";" & ActiveCell.Offset(0, -1).Value
End If
Else
' ignore if there is no X
End If
ActiveCell.Offset(1, 0).Select ' select next cell
Loop
' message body
message = "Hi " & receiver & ", " & "<br>" & "<br>" & "Proceed <b> STARTED </b> and <b> COMPLETED: </b>"
message = message & "<br>" & "<b> Screenshots, Logs, Etc.) </b>" & "<br>"
' creating the email
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.Display ' Display the email, can also send
.To = receiver
.CC = ccreceiver
.BCC = ""
.subject = subject
.HTMLBody = message & "<span>" & RangetoHTML(head) & RangetoHTML(rng) & "</span>" & "<br>" & _
"xxxx</a> Team." & _
"<br>" & "<br>" & .HTMLBody ' the link in the description and the signature
' RangetoHTML function reformats the range given to it into HTML format and paste it into the email
End With
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
On Error GoTo 0
Set OutMail = Nothing ' free memory
Set OutApp = Nothing
Sheets(thissheet).Select ' go back to the original sheet
Cells(rng.Row, "M").Value = " email sent" ' Added new line code from Chandoo to fill status
Cells(rng.Row, "K").Value = Now ' Added new line code from Chandoo
End Sub
Sub Mail_Outlook()
Dim receiver As String
Dim ccReceiver As String
Dim subJect As String
Dim message As String
Dim OutApp As Object
Dim OutMail As Object
Dim thisSheet As String
thisSheet = ActiveSheet.Name ' points to the active sheet in use
Dim head As Range
Dim rng As Range
Dim c As Range
Set rng = Nothing
ccReceiver = ""
On Error Resume Next
receiver = Range("C" & CStr(ActiveCell.Row())).Value
Set rng = Selection.SpecialCells(xlCellTypeVisible)
Set head = Sheets(thisSheet).Range("A2:C2").SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected" & _
vbNewLine & "please correct and try again.", vbOKOnly
Exit Sub
End If
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
' setting subject
Sheets("1. Highlevel ").Select
subJect = Range("C6").Value & " - " & Range("C5").Value & " - Activities"
Sheets("4. MOBILE").Select
Range("I3").Select
Do While ActiveCell.Value <> "End"
If ActiveCell.Value = "X" Or ActiveCell.Value = "x" Then
If HasHyperlink(ActiveCell.Offset(0, -1)) Then
ccReceiver = ccReceiver & ";" & GetAddress(ActiveCell.Offset(0, -1))
Else
ccReceiver = ccReceiver & ";" & ActiveCell.Offset(0, -1).Value
End If
Else
' ignore if there is no X
End If
ActiveCell.Offset(1, 0).Select ' select next cell
Loop
' message body
message = "Hi " & receiver & ", " & "<br>" & "<br>" & "Proceed <b> STARTED </b> and <b> COMPLETED: </b>"
message = message & "<br>" & "<b> Screenshots, Logs, Etc.) </b>" & "<br>"
' creating the email
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.Display ' Display the email, can also send
.To = receiver
.CC = ccReceiver
.BCC = ""
.subJect = subJect
.HTMLBody = message & "<span>" & RangetoHTML(head) & RangetoHTML(rng) & "</span>" & "<br>" & _
"xxxx</a> Team." & _
"<br>" & "<br>" & .HTMLBody ' the link in the description and the signature
' RangetoHTML function reformats the range given to it into HTML format and paste it into the email
End With
Sheets(thisSheet).Select ' go back to the original sheet
'Mark up statuses
For Each c In rng.Cells
Cells(c.Row, "G").Value = " email sent" ' Added new line code from Chandoo to fill status
Cells(c.Row, "K").Value = Now ' Added new line code from Chandoo
Next c
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
On Error GoTo 0
Set OutMail = Nothing ' free memory
Set OutApp = Nothing
End Sub