Ich verwende Excel VBA-Makro zum Senden von automatisierten E-Mails (Outlook 2013), die mit Windows Taskplaner ausgeführt wird (Ich verwende Batch-Datei, um das zu tun) zur angegebenen Zeit jeden Tag. Wenn ich mein Makro ohne Taskplaner ausführen, wird es normal ausgeführt (E-Mails werden gesendet), aber wenn ich den Taskplaner für den Laufzeitfehler 429 verwende, tritt dies nur auf, wenn der VBA-Makro versucht, ein Outlook-Objekt zu erstellen:Excel VBA-Code löst Laufzeitfehler 429 beim Senden von Outlook-E-Mail mit Taskplaner
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application") 'The error happens here
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.to = "[email protected]"
.CC = ""
.BCC = ""
.Subject = "subj"
.Body = "body"
.Attachments.Add ActiveWorkbook.FullName
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Der obige Fehler tritt nur auf, wenn die Outlook-Anwendung auf dem Computer geöffnet ist. Nun, was ich nicht verstehe, ist:
Warum funktioniert die Makro Arbeit in der Regel ohne Task-Scheduler (trotz Outlook geöffnet ist oder nicht) und warum es nicht dort arbeiten?
Wie wird der gesamte Prozess mit Taskplaner ausgeführt und nicht davon abhängig, dass die Outlook App geöffnet oder geschlossen ist? (Ich möchte, dass das Makro ausgeführt wird, unabhängig davon, welche Anwendungen geöffnet/geschlossen sind).
Beratung wäre sehr geschätzt.
Edit: Hier ist der VBScript-Code Ich bin mit Makro auszuführen (in repsonse zu LS_ᴅᴇᴠ Frage):
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
' Create an Excel instance
Dim myExcelWorker
Set myExcelWorker = CreateObject("Excel.Application")
' Disable Excel UI elements
myExcelWorker.DisplayAlerts = False
myExcelWorker.AskToUpdateLinks = False
myExcelWorker.AlertBeforeOverwriting = False
myExcelWorker.FeatureInstall = msoFeatureInstallNone
' Tell Excel what the current working directory is
' (otherwise it can't find the files)
Dim strSaveDefaultPath
Dim strPath
strSaveDefaultPath = myExcelWorker.DefaultFilePath
strPath = WshShell.CurrentDirectory
myExcelWorker.DefaultFilePath = strPath
' Open the Workbook specified on the command-line
Dim oWorkBook
Dim strWorkerWB
strWorkerWB = strPath & "\____DailyReport.xlsm"
Set oWorkBook = myExcelWorker.Workbooks.Open(strWorkerWB)
' Build the macro name with the full path to the workbook
Dim strMacroName
strMacroName = "'" & strPath & "\____DailyReport.xlsm'" & "!Module1.____DailyRep"
on error resume next
' Run the calculation macro
myExcelWorker.Run strMacroName
if err.number <> 0 Then
' Error occurred - just close it down.
End If
err.clear
on error goto 0
'oWorkBook.Save
'oWorkBook.Close <<--- we don't need these two because we close the WB in the VBA macro
myExcelWorker.DefaultFilePath = strSaveDefaultPath
' Clean up and shut down
Set oWorkBook = Nothing
' Don’t Quit() Excel if there are other Excel instances
' running, Quit() will
'shut those down also
if myExcelWorker.Workbooks.Count = 0 Then
myExcelWorker.Quit
End If
Set myExcelWorker = Nothing
Set WshShell = Nothing
Was ist das für ein Excel-Makro, den Sie im Taskplaner abgelegt haben? –
@ LS_ᴅᴇᴠ Ich benutzte das hier beschriebene VBScript: [Excel: Excel auf Windows Taskplaner ausführen] (http://krgreenee.blogspot.com/2006/04/excel-running-excel-on-windows-task.html) und meine Batch-Datei sah so aus: 'start '" "D: \ Dokumente \ Makros \ ___ \ Run__Rep.vbs" ' –
Also, eine andere Frage ... Was enthält VBS? –