I am trying to adapt a loop I used in a different sub to look through my sheet and find the rows where a conditional formatting rule I made has highlighted the cells yellow and send an email out. However, I am getting an application-defined or object-defined error when I try to run it. Any suggestions on how to fix this? Thank you in advance!
Sub Reminder()
Sheets("INVOICES").Activate
Dim start_cell As Range
Dim sheet As Worksheet
Set sheet = Worksheets("INVOICES")
Set start_cell = sheet.Range("B1")
Dim i As Integer
Dim rng As Range
Dim iMsg As Object
Dim iConf As Object
Dim Flds As Variant
Dim TextBody As String
Dim ApprovedTextBody As String
Dim Finfo As String
Dim FilterIndex As Integer
Dim FileName As Variant
Dim Title As String
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Finfo = "All Files (*.*),*.*"
Title = "E-Mail Attachment: Select file to attach."
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields
'mail server details
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mail_server
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Update
End With
Do While Len(start_cell.Cells(i, 1).Value) > 0
If cells("B:U").FormatConditions(1).Formula1 Then
TextBody = "Hello," & vbNewLine & vbNewLine & _
"The attached invoice is still awaiting approval. Kindly review and approve it as " & _
"soon as you get a chance. " & vbNewLine & vbNewLine & Cells(start_cell, 5).Text & _
" Inv " & Cells(start_cell, 4).Text & vbNewLine & "JSID " & _
Cells(start_cell, 1).Text & vbNewLine & Cells(start_cell, 9).Text & vbNewLine & _
Cells(start_cell, 6).Text & " " & Cells(start_cell, 7).Text & vbNewLine & vbNewLine & _
"Thank you," & vbNewLine & "cschoyer"
With iMsg
Set .Configuration = iConf
.To = Cells(start_cell, 12).Text + "@xyz.com"
.CC = "cschoyer@xyz.com"
.BCC = ""
.From = """cschoyer"" <cschoyer@xyz.com>"
.Subject = "Pending Approval " & Cells(start_cell, 5).Text & " Inv " & _
Cells(start_cell, 4).Text & " JSID " & Cells(start_cell, 1).Text
.TextBody = TextBody
.AddAttachment invoice_file_name
.Send
End With
End If
i = i + 1
Loop
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
I get the bug on the line "Do While Len(start_cell.Cells(i, 1).Value) > 0"
Thank you again for any help !
Bookmarks