Hi I was wondering if the VBA code to auto run without opening the workbook/worksheet for the code to work?i know that the event is when open.But is there a way to make it run without opeing?
VBA Code:
Private Sub Workbook_Open()
Dim i As Long
Dim OutApp, OutMail As Object
Dim strto, strcc, strbcc, strsub, strbody As String
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
For i = 2 To Range("C65536").End(xlUp).Row
If Cells(i, 6) <> "Y" Then
If Cells(i, 3) - 7 < Date Then
Set OutMail = OutApp.CreateItem(0)
strto = Cells(i, 4).Value 'email address
strsub = "Project " & Cells(i, 2).Value & " is due on Due date " & Cells(i, 3).Value 'email subject
strbody = "Dear " & Cells(i, 1).Value & vbNewLine & "please update your project status" 'email body
With OutMail
.To = strto
.Subject = strsub
.Body = strbody
.Send
'.display
End With
On Error Resume Next
Cells(i, 5) = "Mail Sent " & Now()
Cells(i, 6) = "Y"
End If
End If
Next
Set OutMail = Nothing
Set OutApp = Nothing
End Sub