如何使用Excel UserForm自动发送Outlook电子邮件?
问题描述:
感谢您的任何帮助。我有一个用户表单,用于收集用户的标准,然后当他们点击提交时打开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
末次
答
您需要使用的Outlook项目Send方法来代替。 Send方法使用为会话指定的默认帐户发送项目。在配置文件中定义多个Microsoft Exchange帐户的会话中,添加到配置文件的第一个Exchange帐户是主Exchange帐户,并且也是会话的默认帐户。要指定其他帐户发送项目,请将SendUsingAccount属性设置为所需的Account对象,然后调用发送方法。
另外,我建议使用收件人属性来添加收件人。该属性返回一个收件人集合,该收集表示Outlook项目的所有收件人。
你好,请罗恩去熊先生的网站,该网站是真正有用的,我敢肯定,你可以找到你即将与Excel [链接](http://www.rondebruin.nl/win/s1发送邮件寻求一切/outlook/mail.htm) – Dubison 2015-02-23 16:02:54