ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 45999|回复: 57

[求助] To: mineshine老师。(Excel自动发邮件延伸问题)

  [复制链接]

TA的精华主题

TA的得分主题

发表于 2009-2-13 00:14 | 显示全部楼层 |阅读模式
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
你好mineshine老师,同事的要求无止境,可惜我又水平有限,不得不再次请教您。。。

以下代码的邮件正文需要设置成为 Times Roman,14号字,并且在从excel表中选择的各个column用蓝色表示。
我用蓝色标出。

Sub AutoMail()
Dim OutlookApp As Object
Dim MailItem As Object
Dim Recipient As Object
Dim i As Integer
For i = 2 To Sheets("CFD").[A65536].End(xlUp).Row
    Set OutlookApp = CreateObject("Outlook.Application")
    Set MailItem = OutlookApp.CreateItem(0)
    Set Recipient = MailItem.Recipients.Add(Sheets("CFD").Range("U" & i).Value)
    MailItem.Subject = "This is auto Email From Kuehne & Nagel Ltd Guangzhou Office"
    MailItem.Body = "致尊敬的经销商:" & vbNewLine & _
    "Dear Dealer:" & vbNewLine & _
    "                              " & vbNewLine & _
    "                              " & vbNewLine & _
    "xxxxxxx广州分公司,由xxxxxx广州配送中心" & vbNewLine & _
    "委托,承运订单号为 (附件" & Sheets("CFD").Range("A" & i).Value & ")的零部件至(附件" & Sheets("CFD").Range("F" & i).Value & ")。" & vbNewLine & _
    "如需查询该票货物的运输状态,请浏览xxxx司的网页http://www.abc.com/。" & vbNewLine & _
    "您的查询号码为 (附件" & Sheets("CFD").Range("B" & i).Value & ")." & vbNewLine & _
    "                              " & vbNewLine & _
    "KN was authorized by Daimler Northeast Asia Parts Trading and Services Co., LTD" & vbNewLine & _
    "Guangzhou PDC to deliver automotive parts under PO   (" & Sheets("CFD").Range("A" & i).Value & ")   to" & vbNewLine & _
    "(" & Sheets("CFD").Range("F" & i).Value & ")." & vbNewLine & _
    "Regarding the transportation status of mentioned shipment, please check on " & vbNewLine & _
    "KN website http://www.kn-portal.com/. " & vbNewLine & _
    "Your tracking number is  (" & Sheets("CFD").Range("B" & i).Value & ")." & vbNewLine & _
    "                              " & vbNewLine & _
    "                              " & vbNewLine & _
    "谢谢!" & vbNewLine & _
    "Thanks for your attention!" & vbNewLine & _
    "                              " & vbNewLine & _
    "                              " & vbNewLine & _
    "xxxxxxx广州分公司" & vbNewLine & _
    "xxxxxxx Guangzhou Branch Office"
    MailItem.Send
    Set OutlookApp = Nothing
    Set MailItem = Nothing
    Set Recipient = Nothing
Next i
End Sub

好多个谢谢!!!!

TA的精华主题

TA的得分主题

发表于 2009-2-13 10:34 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
要配合HTML语法,试看看!!

Sub AutoMail()
Dim OutlookApp As Object
Dim MailItem As Object
Dim Recipient As Object
Dim i As Integer
Dim StrMail As String
For i = 2 To Sheets("CFD").[A65536].End(xlUp).Row
    Set OutlookApp = CreateObject("Outlook.Application")
    Set MailItem = OutlookApp.CreateItem(0)
    Set Recipient = MailItem.Recipients.Add(Sheets("CFD").Range("U" & i).Value)
    MailItem.Subject = "This is auto Email From Kuehne & Nagel Ltd Guangzhou Office"
    StrMail = "<H2>致尊敬的经销商:</H2>" & _
    "<H2>Dear Dealer:</H2><BR><BR>" & _
    "<FONT SIZE=4>xxxxxxx广州分公司,由xxxxxx广州配送中心<BR>" & _
    "委托,承运订单号为 (<Font Face=Times Roman Size=4.5 Color=blue>" & "附件" & Sheets("CFD").Range("A" & i).Value & "</font>)的零部件至(" & "<Font Face=Times Roman Size=4.5 Color=blue>" & "附件" & Sheets("CFD").Range("F" & i).Value & "</font>)。<BR>" & _
    "如需查询该票货物的运输状态,请浏览xxxx司的网页http://www.abc.com/。<BR>" & _
    "您的查询号码为 (" & "<Font Face=Times Roman Size=4.5 Color=blue> " & "附件" & Sheets("CFD").Range("B" & i).Value & "</FONT>).<BR><BR>" & _
    "KN was authorized by Daimler Northeast Asia Parts Trading and Services Co., LTD<BR>" & _
    "Guangzhou PDC to deliver automotive parts under PO   (<Font Face=Times Roman Size=4.5 Color=blue>" & Sheets("CFD").Range("A" & i).Value & "</FONT>)   to<BR>" & _
    "(<Font Face=Times Roman Size=4.5 Color=blue>" & Sheets("CFD").Range("F" & i).Value & "</FONT>).<BR>" & _
    "Regarding the transportation status of mentioned shipment, please check on <BR>" & _
    "KN website http://www.kn-portal.com/. <BR>" & _
    "Your tracking number is  (<Font Face=Times Roman Size=4.5 Color=blue>" & Sheets("CFD").Range("B" & i).Value & "</FONT>).<BR><BR><BR>" & _
    "谢谢!<BR>" & _
    "Thanks for your attention!<BR><BR><BR>" & _
    "xxxxxxx广州分公司<BR>" & _
    "xxxxxxx Guangzhou Branch Office</FONT>"
    MailItem.HTMLBody = StrMail
    MailItem.Send
    Set OutlookApp = Nothing
    Set MailItem = Nothing
    Set Recipient = Nothing
Next i
End Sub

评分

1

查看全部评分

TA的精华主题

TA的得分主题

 楼主| 发表于 2009-2-13 11:09 | 显示全部楼层

回复 3楼 mineshine 的帖子

mineshine老师,您的代码可行, 真是让我好佩服!!!!

衷心感谢你!!!

还有一个问题,如何设置Bold格式的呢?:)

TA的精华主题

TA的得分主题

发表于 2009-2-13 11:21 | 显示全部楼层
Sub AutoMail()
Dim OutlookApp As Object
Dim MailItem As Object
Dim Recipient As Object
Dim i As Integer
Dim StrMail As String
For i = 2 To Sheets("CFD").[A65536].End(xlUp).Row
    Set OutlookApp = CreateObject("Outlook.Application")
    Set MailItem = OutlookApp.CreateItem(0)
    Set Recipient = MailItem.Recipients.Add(Sheets("CFD").Range("U" & i).Value)
    MailItem.Subject = "This is auto Email From Kuehne & Nagel Ltd Guangzhou Office"
    StrMail = "<H2>致尊敬的经销商:</H2>" & _
    "<H2>Dear Dealer:</H2><BR><BR>" & _
    "<FONT SIZE=4>xxxxxxx广州分公司,由xxxxxx广州配送中心<BR>" & _
    "委托,承运订单号为 (<Font Face=Times Roman Size=4.5 Color=blue><B>" & "附件" & Sheets("CFD").Range("A" & i).Value & "</B></font>)的零部件至(" & "<Font Face=Times Roman Size=4.5 Color=blue><B>" & "附件" & Sheets("CFD").Range("F" & i).Value & "</B></font>)。<BR>" & _
    "如需查询该票货物的运输状态,请浏览xxxx司的网页http://www.abc.com/。<BR>" & _
    "您的查询号码为 (" & "<Font Face=Times Roman Size=4.5 Color=blue><B> " & "附件" & Sheets("CFD").Range("B" & i).Value & "</B></FONT>).<BR><BR>" & _
    "KN was authorized by Daimler Northeast Asia Parts Trading and Services Co., LTD<BR>" & _
    "Guangzhou PDC to deliver automotive parts under PO   (<Font Face=Times Roman Size=4.5 Color=blue><B>" & Sheets("CFD").Range("A" & i).Value & "</B></FONT>)   to<BR>" & _
    "(<Font Face=Times Roman Size=4.5 Color=blue><B>" & Sheets("CFD").Range("F" & i).Value & "</B></FONT>).<BR>" & _
    "Regarding the transportation status of mentioned shipment, please check on <BR>" & _
    "KN website http://www.kn-portal.com/. <BR>" & _
    "Your tracking number is  (<Font Face=Times Roman Size=4.5 Color=blue><B>" & Sheets("CFD").Range("B" & i).Value & "</B></FONT>).<BR><BR><BR>" & _
    "谢谢!<BR>" & _
    "Thanks for your attention!<BR><BR><BR>" & _
    "xxxxxxx广州分公司<BR>" & _
    "xxxxxxx Guangzhou Branch Office</FONT>"
    MailItem.HTMLBody = StrMail
    MailItem.Send
    Set OutlookApp = Nothing
    Set MailItem = Nothing
    Set Recipient = Nothing
Next i
End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2009-2-13 11:55 | 显示全部楼层
mineshine老师,无言感激!!!!!!

TA的精华主题

TA的得分主题

 楼主| 发表于 2009-2-13 12:10 | 显示全部楼层

回复 5楼 mineshine 的帖子

mineshine老师,又有问题了...

有没有办法在邮件选取的U栏内输入2个邮件地址,用分号分隔,然后宏会识别这两个邮件地址发2个邮件。或者3个或以上。

TA的精华主题

TA的得分主题

发表于 2009-2-13 13:39 | 显示全部楼层

回复 7楼 canciaw 的帖子

改一句

Sub AutoMail()
Dim OutlookApp As Object
Dim MailItem As Object
Dim Recipient As Object
Dim i, j As Integer
Dim StrMail As String

For i = 2 To Sheets("CFD").[A65536].End(xlUp).Row
    Set OutlookApp = CreateObject("Outlook.Application")
    Set MailItem = OutlookApp.CreateItem(0)
    'Set Recipient = MailItem.Recipients.Add(Sheets("CFD").Range("U" & i).Value)
    MailItem.To = Sheets("CFD").Range("U" & i).Value
    MailItem.Subject = "This is auto Email From Kuehne & Nagel Ltd Guangzhou Office"
    StrMail = "<H2>致尊敬的经销商:</H2>" & _
    "<H2>Dear Dealer:</H2><BR><BR>" & _
    "<FONT SIZE=4>xxxxxxx广州分公司,由xxxxxx广州配送中心<BR>" & _
    "委托,承运订单号为 (<Font Face=Times Roman Size=4.5 Color=blue><B>" & "附件" & Sheets("CFD").Range("A" & i).Value & "</B></font>)的零部件至(" & "<Font Face=Times Roman Size=4.5 Color=blue><B>" & "附件" & Sheets("CFD").Range("F" & i).Value & "</B></font>)。<BR>" & _
    "如需查询该票货物的运输状态,请浏览xxxx司的网页http://www.abc.com/。<BR>" & _
    "您的查询号码为 (" & "<Font Face=Times Roman Size=4.5 Color=blue><B> " & "附件" & Sheets("CFD").Range("B" & i).Value & "</B></FONT>).<BR><BR>" & _
    "KN was authorized by Daimler Northeast Asia Parts Trading and Services Co., LTD<BR>" & _
    "Guangzhou PDC to deliver automotive parts under PO   (<Font Face=Times Roman Size=4.5 Color=blue><B>" & Sheets("CFD").Range("A" & i).Value & "</B></FONT>)   to<BR>" & _
    "(<Font Face=Times Roman Size=4.5 Color=blue><B>" & Sheets("CFD").Range("F" & i).Value & "</B></FONT>).<BR>" & _
    "Regarding the transportation status of mentioned shipment, please check on <BR>" & _
    "KN website http://www.kn-portal.com/. <BR>" & _
    "Your tracking number is  (<Font Face=Times Roman Size=4.5 Color=blue><B>" & Sheets("CFD").Range("B" & i).Value & "</B></FONT>).<BR><BR><BR>" & _
    "谢谢!<BR>" & _
    "Thanks for your attention!<BR><BR><BR>" & _
    "xxxxxxx广州分公司<BR>" & _
    "xxxxxxx Guangzhou Branch Office</FONT>"
    MailItem.HTMLBody = StrMail
    MailItem.Send
    Set OutlookApp = Nothing
    Set MailItem = Nothing
    Set Recipient = Nothing
Next i
End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2009-2-13 14:19 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
报告老师,测试成功了!!! 谢谢...

是不是加一个收件人,只能定义一个邮件地址,而作为To发送,就可以发多个收件人呢?

TA的精华主题

TA的得分主题

发表于 2009-2-13 14:28 | 显示全部楼层

回复 9楼 canciaw 的帖子

我本來也不能确定,想了很多方法,参考之前留的那个英文网页,结果测试成功啦!!

TA的精华主题

TA的得分主题

 楼主| 发表于 2009-2-13 14:35 | 显示全部楼层
谢谢老师,浪费了您的时间去思考,真的抱歉!!!  也希望您的方案可以帮到更多的朋友!
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-12-23 10:48 , Processed in 0.038110 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表