从VBA电子邮件程序发送HTML电子邮件 [英] Sending html email from VBA email program

查看:286
本文介绍了从VBA电子邮件程序发送HTML电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为我的组织编写了一个电子邮件程序,用于处理一些非常特殊的事情,这些事情我可以使用Outlook或Gmail。现在,经理想要给我们的小客户群发送偶尔的电子邮件,但我希望电子邮件正文看起来很专业,不要作为附件发送。我拼凑了一个HTML文档,它存在于所有浏览器中并且已经过验证。我的问题是我无法弄清楚如何指向HTML文档的消息正文。这是显着的代码。

I have written an email program for my organization the handles some very specialized things very well, things I could use Outlook or Gmail for. Now, the manager would like to send an occasional email to our small customer base, but I want the email body tto look professional and not send it as an attachment. I have cobbled together an html document that present in all browsers and has been validated. My problem is I can't figure out how to point the message body at the html document. Here is the salient code.

这是所有设置的地方:

This is where all is set up:

Do While mailRs.EOF = False
'Me.AttachDoc = "C:\EmailFolder\CouponForm.pdf"
  emTo = mailRs.Fields("EmailAddr").Value
  emFrom = "SportsParkInfo@skokieparks.org"
  emSubject = Me.Subject
  emtextBody = Me.TextMessage

以下是发送电子邮件的电话:

Here is a the call for sending the email

Call SendAMessage(emFrom, mailRs.Fields("EmailAddr").Value, _
                   emSubject, emtextBody, emAttach)

代码发送电子邮件离开网络,它通过我们的邮件服务器工作得很好。)

(I got the code for sending the email off the web and it works great through our mail server.)

在上面,在调用@ emtextBody = Me .TextMessage 是我需要用html文档的地址/正文替换 Me.TextMessage 的地方。消息框是ACCESS表单上的文本框。我无法在需要html的ACCESS中找到任何控件。我无法使用html文档的路径,因为这会产生错误。有没有办法绕过这个

In the above, before the call @ emtextBody = Me.TextMessage is where I need to replace Me.TextMessage with the address/body of the html document. And the message box is a textBox on the ACCESS form. I can't find any control in ACCESS that takes html. I can't use the path to the html document because that generates an error. Is there a way of getting around this

如果需要更多信息,我会很乐意提供。

If more information is required I'll be happy to supply it.

感谢您的时间。

jpl

推荐答案

像下面的代码一样。我已经包含了附件以及html格式的元素,但几乎所有可以用html编写的东西都可以在vba中完成。

Use something like the below code. I've included elements for attachment as well as html formatting but pretty much anything you can write in html can also be done within vba.

Sub SharePerformance()

Dim OutApp As Object
Dim OutMail As Object
Dim rng As Range


Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.createitem(0)
'& "<a href=""\\server\folder"">\\server\folder</a>" &
msg1 = "Team,<br><br><b><DL>" & Range("b5").Value & "</b><br><ul><b><u>" & Range("b6").Value & "</b></u>"
msg1 = msg1 & "<DT><a HREF=C:\USER\Desktop\File1.xlsb>"
msg1 = msg1 & Range("b7").Value & "</a><br>"
msg1 = msg1 & "<b><u>" & Range("b9").Value & "</b></u></DL><br><br>"


msg1 = msg1 & "<p><img src=file://" & "C:\temp\Chart1.png" & "></p>" & "<br>"

On Error Resume Next
' Change the mail address and subject in the macro before you run it.

With OutMail
    .To = Range("B1").Value
    .cc = ""
    .BCC = ""
    .Subject = Range("B3").Value
    .HTMLBody = msg1
    '.Attachments.Add ActiveWorkbook.FullName
    '.Attachments.Add ("C:\temp\Chart1.png")
    '.Attachments.Add ("C:\temp\Chart2.png")
    .display
End With
SendKeys "^{ENTER}"
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing

End Sub

这篇关于从VBA电子邮件程序发送HTML电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆