这是我到目前为止的代码:
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 对象的代码:
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")
为什么我不能
ObjShell.Quit
在我调用SendEmail()
函数后做?使用.Quit
给我一个错误。我只想在电子邮件发送后关闭 Outlook 应用程序,但我不知道如何操作。