我有以下幾行代碼。它在Outlook打開時工作正常,但即使Outlook關閉,我也希望它能夠正常工作。我將代碼保留在命令按鈕單擊事件中。如何在outlook關閉時發送郵件
Private Sub btnSend_Click()
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = GetObject("", Outlook.Application)
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "[email protected]"
.CC = ""
.BCC = ""
.Subject = "Test mail from Excel Sheet-OutLook Closed"
.Body = "This is body of the mail"
.Display
.Send
.ReadReceiptRequested = True
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
我試過它與GetObject和CreateObject方法。如果我在關閉Outlook後執行此代碼,它不會顯示任何錯誤,但它不會發送任何郵件。
以下幾行代碼發送郵件,但它們在Outlook的發件箱中排隊。當用戶打開Outlook時,只有他們從發件箱中移出。
Private Sub btnSend_Click()
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "[email protected]"
.CC = ""
.BCC = ""
.Subject = "Test mail from Excel Sheet-OutLook Closed"
.Body = "This is body of the mail"
.Display
.Send
.ReadReceiptRequested = True
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
我沒有看到CreateObject代碼?這應該工作... –
而不是GetObject(「」,Outlook.Application)我已經使用了CreateObject(Outlook.Application)和保持同行。 –
如果我這樣寫,那麼郵件在發件箱中排隊。每當用戶打開前景那麼只有電子郵件被going.'' –