好的,所以我一直在将创可贴放在创可贴之上,用一段简单的代码来获取要发送的电子邮件。我一直在尝试做的是通过 Outlook 发送一封电子邮件。我的第一个问题是runtime object define 287
在以下行:
Set appOutlookRec = appOutlookMsg.Recipients.Add
所以为了反驳我补充说:
Set objNS = appOutlook.GetNamespace("MAPI")
Set olFolder = objNS.GetDefaultFolder(olFolderInbox)
这阻止了这一点。现在电子邮件将形成,我可以使用它.display
来查看我的电子邮件,但是当我尝试使用.send
Outlook 实例时,它会在电子邮件实际发送之前关闭。
为了解决这个问题,我强制打开 Outlook,但我想检查一个实例是否已经打开。要打开我使用的收件箱:
Set appOutlook = CreateObject("Outlook.Application")
Set objNS = appOutlook.GetNamespace("MAPI")
Set olFolder = objNS.GetDefaultFolder(olFolderInbox)
olFolder.Display
我是否过度复杂了自动化过程?还是我走在正确的道路上,有人可以帮助检查资源管理器窗口中是否打开了 Outlook 实例?
谢谢
更新
Const olMailItem = 0
Const olTo = 1
Const olCC = 2
Const olFolderInbox = 6
Dim appOutlook As Object
Dim appOutlookMsg As Object
Dim appOutlookRec As Object
Dim objNS As Object
Dim olFolder As Object
Set appOutlook = CreateObject("Outlook.Application")
Set objNS = appOutlook.GetNamespace("MAPI")
Set olFolder = objNS.GetDefaultFolder(olFolderInbox)
olFolder.Display
'Create a new empty email message
Set appOutlookMsg = appOutlook.CreateItem(olMailItem)
With appOutlookMsg
Set appOutlookRec = appOutlookMsg.Recipients.Add("....@gmail.com")
appOutlookRec.Type = olTo
.Subject = "Testing Closed Tickets"
.Body = "This is just a test."
'.Display
.Send
End With
Set appOutlookMsg = Nothing
Set appOutlook = Nothing
Set appOutlookRec = Nothing