每个小时执行VBA脚本的困难

我试图每小时左右都有这个VBA脚本(发送给我一个电子邮件,如果任务到达了它的到期日)。 我环顾四周,尝试了几个例子,但是我收到了一个消息,我试图运行它。 有人会善意地给它一个快速的样子吗?

谢谢!

Option Explicit Private Sub TaskTracker() Dim FormulaCell As Range Dim FormulaRange As Range Dim NotSentMsg As String Dim MyMsg As String Dim SentMsg As String Dim MyLimit As Double NotSentMsg = "Not Sent" SentMsg = "Sent" 'Equals the MyLimit value it will triger the email MyLimit = Date Set FormulaRange = Me.Range("E5:E35") On Error GoTo EndMacro: For Each FormulaCell In FormulaRange.Cells With FormulaCell If .Value = MyLimit Then MyMsg = NotSentMsg If .Offset(0, 1).Value = NotSentMsg Then strTO = "fmal@ox.com" strCC = "fs@ox.com" strBCC = "" strSub = "Greetings " & Cells(FormulaCell.Row, "B").Value strBody = "Hi Sir, " & vbNewLine & vbNewLine & _ "This email is to notify that you need to do your task : " & Cells(FormulaCell.Row, "B").Value & _ vbNewLine & vbNewLine & "Regards, Yourself" If sendMail(strTO, strSub, strBody, strCC) = True Then MyMsg = SentMsg 'Call Mail_with_outlook2 End If Else MyMsg = NotSentMsg End If Application.EnableEvents = False .Offset(0, 1).Value = MyMsg Application.EnableEvents = True End With Next FormulaCell ExitMacro: Exit Sub EndMacro: Application.EnableEvents = True MsgBox "Some Error occurred." _ & vbLf & Err.Number _ & vbLf & Err.Description Call AutoRun End Sub Sub AutoRun() Application.OnTime Now + TimeValue("00:00:10"), "TaskTracker" End Sub 

据我的理解,脚本在结束之前应该调用AutoRun子句。 但事实并非如此。 当我尝试手动运行AutoRun子本身时,它指出“无法运行macros”* \ Task Tracker.clsm'TaskTracker'。 macros可能不在此工作簿中可用,或者所有macros可能被禁用。

一切工作正常。 感谢大家! (留下一个答案我可以标记这个话题为答案):)

下面的代码完全适合我。 正如Kathara所build议的那样,Call Autorun必须放在Next Formula Cell之后。 此外,我不得不logging一个空白的macros,并复制粘贴循环检查的整个代码才能正常工作!

 Option Explicit Private Sub TaskTracker() Dim FormulaCell As Range Dim FormulaRange As Range Dim NotSentMsg As String Dim MyMsg As String Dim SentMsg As String Dim MyLimit As Double NotSentMsg = "Not Sent" SentMsg = "Sent" MyLimit = Date Set FormulaRange = Range("E5:E35") On Error GoTo EndMacro: For Each FormulaCell In FormulaRange.Cells With FormulaCell If .Value = MyLimit Then MyMsg = SentMsg If .Offset(0, 1).Value = NotSentMsg Then strTO = "Fr@Aion.com" strCC = "" strBCC = "" strSub = "[Task Manager] Reminder that you need to: " & Cells(FormulaCell.Row, "A").Value strBody = "Hello Sir, " & vbNewLine & vbNewLine & _ "This email is to notify that you that your task : " & Cells(FormulaCell.Row, "A").Value & " with the following note: " & Cells(FormulaCell.Row, "B").Value & " is nearing its Due Date." & vbNewLine & "It would be wise to complete this task before it expires!" & _ vbNewLine & vbNewLine & "Truly yours," & vbNewLine & "Task Manager v1.0" If sendMail(strTO, strSub, strBody, strCC) = True Then MyMsg = SentMsg ' Call Mail_with_outlook2 End If Else MyMsg = NotSentMsg End If Application.EnableEvents = False .Offset(0, 1).Value = MyMsg Application.EnableEvents = True End With Next FormulaCell Call AutoRun ExitMacro: Exit Sub EndMacro: Application.EnableEvents = True MsgBox "Some Error occurred." _ & vbLf & Err.Number _ & vbLf & Err.Description End Sub Sub AutoRun() Application.OnTime Now + TimeValue("00:00:20"), "TaskTracker" End Sub 

感谢大家的帮助!