VBA应用程序。OntimeTimeValue不运行

时间:2018-07-27 13:59:43

标签: vba excel-vba

我正在尝试完成一份报告,每天早上7:00发送。我在代码中放入了Application.Ontime TimeValue(“ 7:00:00”),“ DailyReport”。过去运行情况很好,但是在我修改DailyReport子代码中的其他代码(无论如何也不会影响Application.Ontime)并选中“使用DDE忽略其他应用程序”之后,报表不再在上午7:00触发。

大家的帮助,万分感谢!!!!

Option Explicit

Sub DailyReport()
Dim t As String 'Time to send daily Snapshot
Dim pr As Boolean 'Is process running/is there data for yesterday


ThisWorkbook.UpdateLink Name:="Y:\DATA COLLECTION 2018.xlsx"
Application.Calculate
t = Db.Range("C6").Value()
pr = Db.Range("D5").Value()
Db.ChartObjects("Chart 1").Chart.Refresh
Db.ChartObjects("Chart 3").Chart.Refresh
Db.ChartObjects("Chart 4").Chart.Refresh


Dim objOutlook As Object
Dim objMail As Object
Dim rng As Range

    today = Format(Now(), "m/dd/yyyy")

    Set objOutlook = CreateObject("Outlook.Application")
    Set objMail = objOutlook.CreateItem(0)
    Set rng = Db.Range("B8:F16")

    Dim myPic1 As String
    Dim myPic2 As String
    Dim myPic3 As String
    Dim fileName1 As String
    Dim fileName2 As String
    Dim fileName3 As String
    Dim myPath As String
    Dim sj As String

    myPic1 = "Feed.png"
    myPic2 = "T and Vacuum.png"
    myPic3 = "D.png"
    myPath = "C:\Users\lab3\Downloads\"

    fileName1 = myPath & myPic1
    fileName2 = myPath & myPic2
    fileName3 = myPath & myPic3
    Db.ChartObjects("Chart 1").Chart.Export fileName1
    Db.ChartObjects("Chart 3").Chart.Export fileName2
    Db.ChartObjects("Chart 4").Chart.Export fileName3

    With objMail
        Dim cell As Range
        Dim strto As String

        For Each cell In Distribution.Range("A1:A100")
            If cell.Value Like "?*@?*.?*" Then
                strto = strto & cell.Value & ";"
            End If
        Next cell

        If Len(strto) > 0 Then strto = Left(strto, Len(strto) - 1)
        If pr Then sj = "Daily Report " & today Else sj = "Daily Report " & today & " - No new data"
            .To = strto
            .Subject = sj
            .HTMLBody = RangetoHTML(rng) & "<p><p>" & "<img src = '" & fileName1 & "'>" & "<p><p>" & _
            "<img src = '" & fileName3 & "'>" & "<p><p>" & "<img src = '" & fileName2 & "'>"
            .Display

   End With


With Application
        .EnableEvents = True
        .ScreenUpdating = True
     End With

    Application.SendKeys "%s"

    Set objOutlook = Nothing
    Set objMail = Nothing


Db.Range("C5").FormulaR1C1 = "TRUE"
Application.StatusBar = "Ready"
ThisWorkbook.Save
Application.OnTime TimeValue("7:00:00"), "DailyReport", True

End Sub

1 个答案:

答案 0 :(得分:-1)

来自(https://msdn.microsoft.com/en-us/vba/excel-vba/articles/application-ontime-method-excel)的文献资料:

  

将Schedule设置为false可以清除先前设置的具有相同Procedure和EarliestTime值的过程。