作者:胡敏qiang | 来源:互联网 | 2023-05-19 13:19
我有一个包含给定数据的工作表,
![在此输入图像描述](https://img.php1.cn/3cd4a/1eebe/cd5/67cc2e96eddffff8.png)
我需要使用Micorosft outlook以特定日期所需的格式通过电子邮件发送数据(比如说日期是2015年1月5日).请参阅下面
![在此输入图像描述](https://img.php1.cn/3cd4a/1eebe/cd5/6789f68dabde0aed.png)
这就是电子邮件的外观,
![在此输入图像描述](https://img.php1.cn/3cd4a/1eebe/cd5/6789f68dabde0aed.png)
我是业余开发人员,通过VBA格式化电子邮件.代码是在Excel 2007工作簿的模块中编写的,在这里,
Public Function FormatEmail(Sourceworksheet As Worksheet, Recipients As Range, CoBDate As Date)
Dim OutApp As Object
Dim OutMail As Object
Dim rows As Range
On Error GoTo FormatEmail_Error
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
For Each rows In Recipients.Cells.SpecialCells(xlCellTypeConstants)
If rows.value Like "?*@?*.?*" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = rows.value
.Subject = "Reminder"
.Body = "Hi All, " & vbNewLine & _
vbNewLine
.display
End With
On Error GoTo 0
Set OutMail = Nothing
End If
Next rows
On Error GoTo 0
Exit Function
FormatEmail_Error:
Set OutApp = Nothing
Application.ScreenUpdating = True
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure FormatEmail of Module modOutlook"
End Function
Stackoverflow拥有一批专家.热心帮助,并且非常感谢.提前致谢.
问候,
玛尼
1> Ralph..:
如果要创建格式良好的Outlook电子邮件,则需要生成带格式的电子邮件.纯文本电子邮件显然是不够的,因此您必须寻找HTML格式的电子邮件.如果是这种情况,您可能希望使用VBA动态创建HTML代码,以模仿Excel的漂亮视觉表示.
在以下链接http://www.quackit.com/html/online-html-editor/您将找到一个在线HTML编辑器,它允许您准备格式良好的电子邮件,然后向您显示必要的HTML代码得到这种格式.之后,您只需要使用VBA将电子邮件正文设置为此HTML代码
.HTMLBody = "your HTML code here"
代替
.Body = "pure text email without formatting"
如果这还不够,并且您想要将Excel的部分内容复制/粘贴到该电子邮件中,那么您将必须复制部分Excel,将它们另存为图片,然后将图片添加到您的电子邮件中(再次使用HTML) ).如果这是您想要的,那么您将在此处找到解决方案:
使用VBA代码如何在Excel 2003中将Excel工作表导出为图像?