2015-02-23 131 views
0

感謝您的任何幫助。我有一個用戶表單,用於收集用戶的標準,然後當他們點擊提交時打開Outlook並將該數據通過電子郵件發送給我。如何使用Excel UserForm自動發送Outlook電子郵件?

我有2個問題。首先,當我嘗試使用SENDKEYS方法時,我遇到了拼寫檢查功能,可以阻止實際發送的電子郵件,而無需用戶通過它。有沒有辦法繞過拼寫檢查併發送電子郵件?

其次,我找不到一種實際發送電子郵件的方式,而不使用SENDKEYS,但我確信有更好的方式發送電子郵件,而不是使用TAB鍵筆觸操作窗口。

Private Sub SubmitButton_Click() 
Dim OutApp As Object 
Dim OutMail As Object 
Dim strBody, RequestName, ProductName, Month, TestName, Summary As String 

If Me.RequesterNameTxt.Value <> "" And Me.ProductCombo.Value <> "" And Me.MonthCombo.Value <> "" And Me.TestNameCombo <> "" Then 
Set OutApp = CreateObject("Outlook.Application") 
Set OutMail = OutApp.CreateItem(0) 

RequestName = Me.RequesterNameTxt.Value 
ProductName = Me.ProductCombo.Value 
Month = Me.MonthCombo.Value 
TestName = Me.TestNameCombo.Value 
Summary = Me.SummaryTxt.Value 


strBody = "<HTML><BODY>" 
strBody = "Requester Name: " & RequestName & "<BR>" & "Product Name: " & ProductName & "<BR>" & "Month: " & Month & "<BR>" & _ 
"Test Name: " & TestName & "<BR>" & "<BR>" & "Summary of Request: " & Summary 
strBody = strBody & "</BODY></HTML>" 

On Error Resume Next 
With OutMail 
    .To = "[email protected];" 
    .CC = "" 
    .bcc = "" 
    .Subject = "QA Service Request" 
    .htmlBody = strBody 
    .send 'This fixed my issue. I had this as .Display which opens email up and doesn't send 
End With 
On Error GoTo 0 
Set OutMail = Nothing 
Set OutApp = Nothing 
Application.SendKeys ("%s") 
    Else: MsgBox "Please fill out all form data before submitting request. Thank you!" 
End If 

末次

+0

你好,請羅恩去熊先生的網站,該網站是真正有用的,我敢肯定,你可以找到你即將與Excel [鏈接](http://www.rondebruin.nl/win/s1發送郵件尋求一切/outlook/mail.htm) – Dubison 2015-02-23 16:02:54

回答

1

您需要使用的Outlook項目Send方法來代替。 Send方法使用爲會話指定的默認帳戶發送項目。在配置文件中定義多個Microsoft Exchange帳戶的會話中,添加到配置文件的第一個Exchange帳戶是主Exchange帳戶,並且也是會話的默認帳戶。要指定其他帳戶發送項目,請將SendUsingAccount屬性設置爲所需的Account對象,然後調用發送方法。

另外,我建議使用收件人屬性來添加收件人。該屬性返回一個收件人集合,該收集表示Outlook項目的所有收件人。