如何使用 Excel UserForm 自动发送 outlook 邮件?
How to send outlook email automatically using Excel UserForm?
感谢您对此提供的任何帮助。我有一个我制作的用户表单,它从用户那里收集标准,然后当他们点击提交时,它会打开 Outlook 并将该数据通过电子邮件发送给我。
我有 2 个问题。第一个是,当我尝试使用 SENDKEYS 方法时,我 运行 进入了拼写检查功能,阻止了电子邮件的实际发送,而无需用户通过它。有没有办法绕过拼写检查并发送电子邮件?
其次,我找不到不使用 SENDKEYS 就自动发送电子邮件的方法,但我确信有更好的方法发送电子邮件,而不是使用 TAB 操作 window击键。
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 = "example@gmail.com;"
.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
结束子
您需要使用Send method of Outlook items instead. The Send method sends an item using the default account specified for the session. In a session where multiple Microsoft Exchange accounts are defined in the profile, the first Exchange account added to the profile is the primary Exchange account, and is also the default account for the session. To specify a different account to send an item, set the SendUsingAccount property to the desired Account对象,然后调用发送方法。
另外,我建议使用收件人 属性 来添加收件人。 属性 returns 代表 Outlook 项目的所有收件人的收件人集合。
感谢您对此提供的任何帮助。我有一个我制作的用户表单,它从用户那里收集标准,然后当他们点击提交时,它会打开 Outlook 并将该数据通过电子邮件发送给我。
我有 2 个问题。第一个是,当我尝试使用 SENDKEYS 方法时,我 运行 进入了拼写检查功能,阻止了电子邮件的实际发送,而无需用户通过它。有没有办法绕过拼写检查并发送电子邮件?
其次,我找不到不使用 SENDKEYS 就自动发送电子邮件的方法,但我确信有更好的方法发送电子邮件,而不是使用 TAB 操作 window击键。
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 = "example@gmail.com;"
.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
结束子
您需要使用Send method of Outlook items instead. The Send method sends an item using the default account specified for the session. In a session where multiple Microsoft Exchange accounts are defined in the profile, the first Exchange account added to the profile is the primary Exchange account, and is also the default account for the session. To specify a different account to send an item, set the SendUsingAccount property to the desired Account对象,然后调用发送方法。
另外,我建议使用收件人 属性 来添加收件人。 属性 returns 代表 Outlook 项目的所有收件人的收件人集合。