Excel VBA 可以使用 Outlook 客户端来发送电子邮件。下面提供一个简单的示例代码:
Sub SendEmail()
Dim OutApp As Object
Dim OutMail As Object
Dim strto As String, strcc As String, strbcc As String, strsub As String, strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strto = "recipient1@example.com; recipient2@example.com"
strcc = "ccaddress@example.com"
strbcc = "bccaddress@example.com"
strsub = "邮件主题"
strbody = "邮件正文"
On Error Resume Next
With OutMail
.To = strto
.CC = strcc
.BCC = strbcc
.Subject = strsub
.HTMLBody = strbody
.Display '或 .Send 发送
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
在上述代码中,您可以将电子邮件的收件人、抄送、密送、主题和正文等信息替换为您实际需要的信息。另外,通过 .Display 方法,您可以启动 Outlook 客户端并显示电子邮件,这样您可以检查邮件内容并手动发送。如果您想自动发送,只需用 .Send 方法替换 .Display 即可。