[英]Excel VBA code to read a username from a cell then send an email to that user
在创建Excel VBA代码时,我需要一些帮助,该代码将从Excel单元格中读取一行用户名,然后通过在Outlook联系人列表中搜索用户的电子邮件地址,向所有这些用户发送电子邮件。
我设法编写了从电子表格中调出Outlook的撰写电子邮件对话框的代码。
您可以在范围用于与邮件和调用这个PROC发送电子邮件
Public Sub SendMail(MailTO As String, MailSubject As String, MailBody As String)
'http://officevb.com
Dim appOL As Object
Dim myEmail As Object
Dim TxtHello As String
Set appOL = CreateObject("Outlook.Application")
Set myEmail = appOL.CreateItem(olMailItem)
'Use hour to create a text
Select Case Hour(Time)
Case Is <= 12
TxtHello = "Good Morning," & vbNewLine
Case Is >= 12
TxtHello = "Good Afternoom," & vbNewLine
Case Is >= 18
TxtHello = "Good Night," & vbNewLine
End Select
With myEmail
.display
.Recipients.Add MailTO
.Subject = MailSubject
.Body = TxtHello & MailBody
.Send
End With
Set myEmail = Nothing
Set appOL = Nothing
End Sub
称这些子传递这些参数
sendMail“ Mail@yourContact.com”,“测试”,“这是一封自动邮件”
[]的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.