[英]Create a Dynamic Outlook Email using Access VBA
Here is my current setup...这是我目前的设置...
I have an Access project tracking database with project description values (example: Project_ID) and I have a button "Create Email" which I've successfully gotten to open Outlook, pick an Outlook draft, and automatically generate the appropriate subject line.我有一个带有项目描述值(例如:Project_ID)的 Access 项目跟踪数据库,我有一个按钮“创建电子邮件”,我已经成功打开 Outlook,选择 Outlook 草稿,并自动生成适当的主题行。
However, I have no clue where to start on this next step.但是,我不知道从哪里开始下一步。 Any help is appreciated!任何帮助表示赞赏!
I would like the Outlook email to have dynamic fields that are linked to the fields in my Access database.我希望 Outlook 电子邮件具有链接到我的 Access 数据库中的字段的动态字段。 I'm not even sure if I should be trying to code in Access or in Outlook for this step!我什至不确定我是否应该尝试在 Access 或 Outlook 中为这一步编码!
Example of what I want:我想要的例子:
NAME,姓名,
Attached are your documents for:附件是您的文件:
Project_ID Project_Name Project_Type <--Values from my Access database Project_ID Project_Name Project_Type <--来自我的 Access 数据库的值
Sincerely,真挚地,
my signature我的签名
you should code in MS Access.你应该在 MS Access 中编码。 a pseudo code would be:伪代码是:
call this like称之为
send_email_message "to@to.to","","","Email subject","Add your email content/body like project id= &field1, project name = field2 and so on"
you can attach more than one file just join the document name with a ";"您可以附加多个文件,只需用“;”加入文档名称即可delimiter.分隔符。 like喜欢
"C;\\file1.txt;c:\\File2.txt" "C;\\file1.txt;c:\\File2.txt"
here a sending email function: this function uses outlook objects (import them in reference) or change it to late binding by vba.createobject("outlook.application")这里是发送电子邮件功能:此功能使用 Outlook 对象(在参考中导入它们)或通过 vba.createobject("outlook.application") 将其更改为后期绑定
Function SEND_EMAIL_MESSAGE(mTo As String, mCC As String, mBC As String, mSubject As String, mBody As String, Optional useOwnSignature As Boolean = False, Optional DisplayMsg As Boolean = False, Optional isHTML As Boolean = False, Optional AttachmentPath = "") As Boolean
'---------------------------------------------------------------------------------------
' Procedure : SEND_EMAIL_MESSAGE
' Author : KRISH KM
' Date : 01/09/2013
' Purpose : Send emails using outlook
'---------------------------------------------------------------------------------------
'
' Please check the reference for Microsoft Outlook 14.0 object library for outlook 2010.
Dim oAPP As Outlook.Application
Dim oMail As Outlook.MailItem
Dim oAPPAttach As Outlook.Attachment
Dim mSignature As String
On Error GoTo ERROR_EMAIL
' Create the Outlook session.
Set oAPP = New Outlook.Application
' Create the message.
Set oMail = oAPP.CreateItem(olMailItem)
With oMail
' Add the To recipient(s) to the message.
.to = mTo
.cc = mCC
.BCC = mBC
.Subject = mSubject
If useOwnSignature Then .BodyFormat = olFormatHTML
.Display
If useOwnSignature Then
If isHTML Then
mSignature = .HTMLBody
.HTMLBody = mBody & mSignature
Else
mSignature = .body
.body = mBody & mSignature
End If
Else
.body = mBody
End If
' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Dim mFiles() As String
If (VBA.Right(AttachmentPath, 1)) <> ";" Then AttachmentPath = AttachmentPath & ";"
mFiles = VBA.Split(AttachmentPath, ";")
Dim i As Integer
For i = 0 To UBound(mFiles) - 1
If Not mFiles(i) = "" Then .Attachments.Add (mFiles(i)) 'Set oAPPAttach = .Attachments.Add(mFiles(i))
Next i
End If
' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Send
End If
End With
SEND_EMAIL_MESSAGE = True
EXIT_ROUTINE:
On Error GoTo 0
Set oAPP = Nothing
Set oMail = Nothing
Exit Function
ERROR_EMAIL:
SEND_EMAIL_MESSAGE = False
GoTo EXIT_ROUTINE
End Function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.