Hi All,
I am getting run time error 13 i.e type mismatch in the below section (alert2) while sending email to user.
Could anyone guide me
The entire code below.
I am getting run time error 13 i.e type mismatch in the below section (alert2) while sending email to user.
Could anyone guide me
Code:
If ((ActiveWorkbook.Worksheets(sht1).Cells(i, 14) - Date) = -5 Or (ActiveWorkbook.Worksheets(sht1).Cells(i, 14) - Date) = -3 Or _
(ActiveWorkbook.Worksheets(sht1).Cells(i, 14) - Date) = -1) Then
Call Fire_mail(i, "alert2")
End If
The entire code below.
Code:
Sub MYMACRO()
Dim rc1, rc2 As Long
Dim sht1 As String
sht1 = "Master sheet"
sht2 = "Archive"
rc1 = ActiveWorkbook.Sheets(sht1).UsedRange.Rows.Count
Dim i As Long
For i = 2 To rc1
If ((ActiveWorkbook.Worksheets(sht1).Cells(i, 9) - Date) = -1) Then
Call Fire_mail(i, "alert1")
End If
If ((ActiveWorkbook.Worksheets(sht1).Cells(i, 14) - Date) = -5 Or (ActiveWorkbook.Worksheets(sht1).Cells(i, 14) - Date) = -3 Or _
(ActiveWorkbook.Worksheets(sht1).Cells(i, 14) - Date) = -1) Then
Call Fire_mail(i, "alert2")
End If
Next i
End Sub
Private Sub Fire_mail(x As Long, str As String)
Dim App As Object
Dim item As Object
Dim sMsgBody As String
Dim sht1
sht1 = "Master sheet"
If (str = "alert1") Then
esubject = "alert1"
sMsgBody = "TEST1"
ebody = sMsgBody
End If
If (str = "alert2") Then
esubject = "alert2"
sMsgBody = "test2"
ebody = sMsgBody
End If
sendto = ActiveWorkbook.Worksheets(sht1).Cells(x, 20)
ccto = ActiveWorkbook.Worksheets(sht1).Cells(x, 19)
Set App = CreateObject("Outlook.Application")
Set itm = App.CreateItem(olMailItem)
With itm
.Subject = esubject
.To = sendto
.CC = ccto
.Body = ebody
.Display
End With
Set App = Nothing
Set itm = Nothing
End Sub