简体   繁体   English

Excel VBA代码从单元格中读取用户名,然后向该用户发送电子邮件

[英]Excel VBA code to read a username from a cell then send an email to that user

I require some help in creating Excel VBA code which will read a row of usernames from cells in Excel and then send an email to all those users by searching for the users email address in the Outlook contacts list. 在创建Excel VBA代码时,我需要一些帮助,该代码将从Excel单元格中读取一行用户名,然后通过在Outlook联系人列表中搜索用户的电子邮件地址,向所有这些用户发送电子邮件。

I have managed to write the code that will bring up outlook's compose email dialog box from the spreadsheet. 我设法编写了从电子表格中调出Outlook的撰写电子邮件对话框的代码。

You can use for in range with mails and call this proc to send email 您可以在范围用于与邮件和调用这个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

call this sub passing these parameters 称这些子传递这些参数

sendMail "Mail@yourContact.com","Test","This is a automatic mail" sendMail“ Mail@yourContact.com”,“测试”,“这是一封自动邮件”

[]´s []的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 VBA代码可从Excel发送个性化电子邮件 - VBA code to send personalized email from excel Excel VBA - 从代码中读取单元格值 - Excel VBA - read cell value from code Excel VBA代码从底部的收件箱中读取Outlook电子邮件 - Excel vba code to read outlook email from inbox from bottom Excel VBA - 从单元格读取时,代码将十进制转换为整数 - Excel VBA - Code is converting a decimal to integer when read from cell 从带有 Excel 的文本单元格发送具有指定粗体/大小/颜色/下划线文本格式的 Email VBA - Send Email With Specified Bold/Size/Color/Underline Text Format from a Text Cell with Excel VBA 没有从Excel-VBA发送电子邮件的权限 - No permissions to send email from Excel-VBA vba从excel发送带有发件人标志的电子邮件 - vba send email from excel with flag for sender Excel VBA 按钮根据单元格值保存工作簿并发送 email - Excel VBA button to save workbook based on cell values and send email Excel VBA 代码从 email 帐户从 Z038E648F69B23B2A54ZDAF26 发送电子邮件(不工作)。 - Excel VBA code to send emails from a specific shared email Account from Outlook not working (.sentonbehalfof) VBA Excel-如果一列中的单元格包含电子邮件地址,而另一列中的单元格是“ SOLD”,则发送电子邮件 - VBA Excel - If cell in one column contains email address and cell in another column is “SOLD” , send email
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM