I am getting the error mentioned in the title while running a program to send emails through outlook. Can anyone please help? It highlights the 2nd line -
enter image description hereDim olApp As Outlook.Application
Code:
Sub send_mail(address As String, subject As String, mail_body As String)
'
'
Dim **olApp As Outlook.Application**
Set olApp = CreateObject("Outlook.Application")
Dim olMail As Outlook.mailitem
Set olMail = olApp.CreateItem(olMailItem)
olMail.To = address
olMail.subject = "Maintenance Activity at: " & subject
olMail.Body = "Equipment to be maintained: " & mail_body
olMail.CC = Sheets("Expiry").Range("M8").Value
olMail.send
End Sub
Sub mass_mail()
n = Now()
MsgBox "date: " & n
If MsgBox("Are You Sure? ", vbYesNo, " Warning! ") = vbYes Then
Dim row_number As Integer
row_number = 4
Do
DoEvents
row_number = row_number + 1
If Range("D" & row_number).Value >= n And Range("D" & row_number).Value < (n + 30) Then
Call send_mail(Sheet1.Range("L" & row_number), Sheet1.Range("C" & row_number), Sheet1.Range("D" & row_number))
MsgBox "Date: " & Range("D" & row_number).Value
End If
Loop Until row_number = 10
MsgBox ("Messages(s) Sent!")
End If
End Sub