gpt4 book ai didi

excel - 使用任务计划程序从 PowerShell 创建电子邮件(运行时错误 429)

转载 作者:行者123 更新时间:2023-12-04 22:28:46 29 4
gpt4 key购买 nike

在执行某些分析后,我创建了几个脚本来发送电子邮件。这以前有效。现在一些脚本失败并给出以下错误消息:

run-time error '429':
ActiveX component can't create object


然后它将 Outlook 对象代码行称为错误。
该脚本在我退出 MS Outlook 时运行,如果 Outlook 正在运行则出错。我使用任务计划程序来运行它,Outlook 通常会运行。
Private Sub Send_Ratings_Email()

Dim OutApp As Object, OutMail As Object
Dim rng As Range
Dim StrBody As String
StrBody = "Please find Maturities for the Current Week Below: "

Application.ScreenUpdating = False
On Error Resume Next
Set OutApp = GetObject(, "Outlook.Application")
On Error GoTo 0
If OutApp Is Nothing Then Set OutApp = GetObject("Outlook.Application")

On Error GoTo cleanup

Set OutMail = OutApp.CreateItem(0)
On Error Resume Next

Call AddAzureLabel(OutMail, "Restricted - Internal")
With OutMail
.To = " example.com"
.Subject = "Weekly Maturities - W/C " & Format(Now, "dd-mmm-yy")
.HTMLBody = StrBody & RangetoHTML(rng)
.Display 'Or use .Send
End With
On Error GoTo 0
Set OutMail = Nothing

cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
Powershell 脚本在手动运行时有效。

最佳答案

您正在创建一个 Outlook 实例,如果它无法运行,则检查它是否已经在运行并获取正在运行的应用程序,如果没有,则创建一个:

On Error Resume Next
Set OutApp = GetObject(, "Outlook.Application")
On Error GoTo 0
If OutApp Is Nothing Then Set OutApp = CreateObject("Outlook.Application")

关于excel - 使用任务计划程序从 PowerShell 创建电子邮件(运行时错误 429),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55221895/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com