Может ли кто-нибудь объяснить, как я могу передать счетчик цикла x в качестве аргумента для подпрограммы email_send
в application.ontime
процедуре.
Найдите прикрепленный код, который я написал для отправки напоминания по электронной почте на основе различных типов рисунка.
Dim x As Long
Sub drawings()
lastrow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For x = 2 To lastrow
If Cells(x, "F") = "Type-1" And Cells(x, "H") = "" Then
Cells(x, "H").Value = 1
time1 = Now() + TimeValue("00:02:00")
Application.OnTime time1, "'email_send" & x & "'"
ElseIf Cells(x, "F") = "Type-2" And Cells(x, "H") = "" Then
Cells(x, "H").Value = 1
time2 = Now() + TimeValue("00:04:00")
Application.OnTime time2, "'email_send" & x & "'"
ElseIf Cells(x, "F") = "Type-3" And Cells(x, "H") = "" Then
Cells(x, "H").Value = 1
time3 = Now() + TimeValue("00:08:00")
Application.OnTime time3, "'email_send" & x & "'"
ElseIf Cells(x, "F") = "Type-4" And Cells(x, "H") = "" Then
Cells(x, "H").Value = 1
time4 = Now() + TimeValue("00:10:00")
'time4 = time4 + 5
Application.OnTime time4, "'email_send" & x & "'"
MsgBox time4
End If
MsgBox Cells(x, "A")
Next x
End Sub
Sub email_send(ByVal x As Long)
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
'MsgBox "hello"
.To = Cells(2, 9).Value
.Subject = "Case ID " & Cells(x, "A") & " (" & Cells(x, "B") & ") Deadline Approaching"
.Body = "Please complete your assigned drawing asap."
.Display
.Send
End With
End Sub
Я новичок в VBA, поэтому я прошу вас, ребята, найти ошибки в моем коде и предложить изменения.
Редактировать: Спасибо, что помогли мне пройти через шаги, ноПроблема в том, что я получаю неожиданную ошибку, когда следую за ними.Я хотел приложить фотографию ошибки, но не могу, потому что у меня недостаточно очков.