【发布时间】:2018-07-27 13:59:43
【问题描述】:
我正在努力完成一份报告,并在每天早上 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
【问题讨论】:
-
but after I modified some other codes in DailyReport sub你到底修改了什么代码?请更新您的问题,让我们知道。