0
我創建了一個VBA腳本,用於在引發時發送圖形的電子郵件。我正試圖設置一個計劃的工作,每天早上9:30發送電子郵件。VBS腳本可以手動運行,但不能通過調度程序運行
我創建了一個運行良好的VBS腳本,當我調用它(即cscript.exe EmailDailyBurnDown.VBS)時,但通過調度程序引發時該腳本不起作用。你能幫我嗎?
EmailDailyBurnDown.VBS
Dim ObjExcel, ObjWB
Set ObjExcel = CreateObject("Excel.Application")
Set ObjWB = ObjExcel.Workbooks.Open("C:\20170814_Promotion Work Backlog_V1.0.9.xlsm")
ObjExcel.Visible = False
ObjExcel.DisplayAlerts = False
ObjExcel.AskToUpdateLinks = False
ObjExcel.AlertBeforeOverwriting = False
'vbs opens a file specified by the path below
'either use the Workbook Open event (if macros are enabled), or Application.Run
ObjExcel.Application.Run "SendBurnDownChartViaEmail"
ObjWB.Save
ObjWB.Close
ObjExcel.Quit
Set ObjWB = Nothing
Set ObjExcel = Nothing
WScript.Echo "Finished."
WScript.Quit
VBA腳本
Sub SendBurnDownChartViaEmail()
Dim OutApp As Object
Dim OutMail As Object
Dim Fname As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
'File path/name of the gif file
Fname = Environ$("temp") & "\My_Sales1.gif"
'Save Chart named "Chart 1" as gif file
ActiveWorkbook.Worksheets("Hidden").ChartObjects("Chart 1").Chart.Export _
Filename:=Fname, FilterName:="GIF"
'MsgBox (Fname)
On Error Resume Next
With OutMail
.To = "[email protected]"
.CC = ""
.BCC = ""
.Subject = "FBT Sprint " & Worksheets("5. Capacity & Sprint Planning").Range("E11").Value & " Burn Down - " & Date
.Attachments.Add Fname
.HTMLBody = "<html>" & "<img src='cid:My_Sales1.gif'></html>"
.Send 'or use .Display
'.Display
End With
On Error GoTo 0
'Delete the gif file
Kill Fname
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
阿克沙伊
棒極了!那就是訣竅。非常感謝你! – user3304587