我有一项任务是计算包含特定文本的行数并在电子邮件上打印该值。
Public Function First()
Dim Source As Workbook
Dim Var1 As Integer
Dim Var10 As Integer
Dim Source2 As Workbook
Set Source = Workbooks.Open("C:\Users\HP\Desktop\IN INPROG.xlsx")
Var1 = Application.WorksheetFunction.CountIf(Range("M1:M100"), "Orange")
Source.Close SaveChanges:=False
Set Source2 = Workbooks.Open("C:\Users\HP\Desktop\SR INPROG.xlsx")
Var10 = Application.WorksheetFunction.CountIf(Range("M1:M100"), "Orange")
Source2.Close SaveChanges:=False
eTo = "orange@aod.au"
esubject = Format(Date, "d/mmmm/yyyy") & " " & "Weekly Open Incident Reminder"
ebody = "Dear All," & vbCrLf & "" & vbCrLf & "" & vbCrLf & "Orange: " & "SR: " & Var10 & " IN: " & Var1
Set app = CreateObject("Outlook.Application")
Set itm = app.createitem(0)
On Error Resume Next
With itm
.Subject = esubject
.To = eTo
.body = ebody
.display
即使“橙色”确实存在于其中一行中,我的代码也会将所有值返回为“0”。