I have an excel document that when it's opened it needs to loop through each record and if the date in column (G) is < 90 days ahead, an email needs to be sent to someone.
Here is the code for the loop. All of a sudden it's telling me that an Run-time error '424': "Object Required" and goes to:
For Each cell In rng
Loop was working not sure where that came from.
In the email I need to reference column (A) (Employer Name) and Column (B) (Inspection ID) in the email and not sure how to do that.
Help please,
Here is the code for the loop. All of a sudden it's telling me that an Run-time error '424': "Object Required" and goes to:
For Each cell In rng
Code:
Private Sub Workbook_Open()
Dim rng As Range, cell As Range
'Dim FinalRow As Integer
For Each cell In rng
If cell.Value < Date + 90 Then
MsgBox cell.Value
Call EmailComment
End If
'Next i
Next cell
End Sub
Loop was working not sure where that came from.
In the email I need to reference column (A) (Employer Name) and Column (B) (Inspection ID) in the email and not sure how to do that.
Code:
Sub EmailComment()
'For Tips see: [URL="http://www.rondebruin.nl/win/winmail/Outlook/tips.htm"][COLOR=#0066cc]http://www.rondebruin.nl/win/winmail/Outlook/tips.htm[/COLOR][/URL]
'Working in Office 2000-2013
Dim xDate As Date, NotifDate As Date, InspEmployer As String, InspID
Dim i As Long
xDate = cell.Value
NotifDate = xDate - 90
InspEmployer = testInspEmployer
InspID = testInspID
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "Inspection Report Needed for " & InspEmployer & " - " & InspID & " - " & xDate & vbNewLine & vbNewLine
On Error Resume Next
With OutMail
.To = "MyEmail"
.CC = ""
.BCC = ""
.Subject = "Report Needed!"
.Body = strbody
'You can add a file like this
'.Attachments.Add ("C:\test.txt")
.Display 'or use .Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Help please,