【问题标题】:could not create object named "Outlook.Application" 8008005 in VBS无法在 VBS 中创建名为“Outlook.Application”的对象 8008005
【发布时间】:2017-04-09 17:15:06
【问题描述】:

我有以下用于发送电子邮件的脚本。当我使用命令在 普通 cmd 窗口 上运行此脚本时

EmailTo.vbs "email" "Subject" "msgBody"

我在收件箱中收到了电子邮件,但是当我在管理命令窗口中运行此邮件时,我收到错误消息: 错误:无法创建名为“Outllok.Application”的对象 代码:8008005 来源:WScript.CreateObject

对于自动化,我需要在管理员命令模式下运行这个 vbs。但它不在管理员模式下运行。

Dim ToAddress
Dim MessageSubject
Dim MessageBody
Dim MessageAttachment
addAttachment = 0

Dim ol, ns, newMail


ToAddress = Wscript.Arguments(0)
MessageSubject = Wscript.Arguments(1)
MessageBody = Wscript.Arguments(2)

if Wscript.Arguments.Count > 3 Then 
addAttachment=1 
MessageAttachment = Wscript.Arguments(3)
End If

' connect to Outlook
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")

Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf

' validate the recipient, just in case...
Set myRecipient = ns.CreateRecipient(ToAddress)
myRecipient.Resolve
If Not myRecipient.Resolved Then
  MsgBox "Unknown recipient"
Else
  newMail.Recipients.Add(ToAddress)
  if addAttachment = 1 Then newMail.Attachments.Add(MessageAttachment).Displayname = "Check this out" End If
  newMail.Send
End If

Set ol = Nothing

【问题讨论】:

  • CreateObject试试看,不要在前面加WScript

标签: vba command-line vbscript outlook admin


【解决方案1】:

我认为您在创建邮件项时可能需要延迟绑定:

Set newMail = ol.CreateItem(0)

olMailItem 枚举为0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-13
    • 1970-01-01
    • 2011-08-18
    • 2015-02-25
    • 1970-01-01
    相关资源
    最近更新 更多