【发布时间】:2015-08-25 03:37:12
【问题描述】:
这是我目前的代码:
Option Explicit
Call OpenOutlook()
Function OpenOutlook()
Dim ObjShell
Set ObjShell = CreateObject("WScript.Shell")
ObjShell.Run("Outlook.exe")
Call SendEmail()
'I tried closing from here but this didn't work either
'ObjShell.Quit
End Function
Function SendEmail()
'Declaring variables used through out this function
Dim ObjOutlook
Dim objMail
Set ObjOutlook = CreateObject("Outlook.Application")
'CreateItem(0) opens a New Email window...MailItem
set objMail = ObjOutlook.CreateItem(0)
objMail.Display
'MailItem Options
objMail.to = "test@mail.com.com"
'objMail.cc = "test2@mail.com"
objMail.Subject = "Did it work!?"
objMail.Body = "If you got this email, my VBs test worked!"
'objMail.Attachments.Add("C:\Attachment\abc.jpg")
objMail.Send
'This didn't work either
'If objMail.Sent = True Then
'ObjOutlook.Quit
'End If
'Quit closes Outlook like I want but it doesn't wait for the email to send
'ObjOutlook.Quit
End Function
我正在尝试使用 VBScript 自动化:
- 打开 Outlook
- 发送电子邮件
- 等待电子邮件发送(发件箱完成发送)
- 发送电子邮件后关闭 Outlook
我被困在哪里:
-
首先,我在打开 Outlook 时遇到了问题。下面是我用来创建 Outlook 对象的代码:
Set ObjOutlook = CreateObject("Outlook.Application") 'CreateItem(0) opens a New Email window...MailItem set objMail = ObjOutlook.CreateItem(0) objMail.Display我做了什么(甚至不确定这是否是正确的做法):
Set ObjShell = CreateObject("WScript.Shell") ObjShell.Run("Outlook.exe")为什么我不能在调用
SendEmail()函数后只做ObjShell.Quit?使用.Quit给我一个错误。 我只想在电子邮件发送后关闭 Outlook 应用程序,但不知道如何操作。
【问题讨论】:
-
您需要使用 Outlook 吗?大多数 VBScripter 使用 CDO 库来发送电子邮件。见this。
标签: vbscript outlook.application