我正在为我的学校制作一个系统,数据库可以在每次需要打印工作表时发送一封电子邮件给资源部。
该表的字段是:
若要发送电子邮件,用户将填写一组参数查询。应该发送电子邮件,而不是即将出现的查询结果。查询应该包含以下字段:
电子邮件应包含以下信息,这些信息对应于在查询中输入的数据:
到目前为止下载我的数据库,单击此处。
我想在VBA代码中这样做。你能引导我沿着正确的路线做这件事吗?任何代码建议都是有帮助的,因为我是VBA新手。谢谢
发布于 2016-01-07 16:06:13
首先,单击"Tools“然后单击" references”,将“MicrosoftOutlook14.0对象库”添加到引用中(您可能有一个与14.0不同的数字)。我有下面的代码,比您要求的要多一点,但是它会工作的。签名参数是文本主体作为字符串。在创建字符串时,使用" vbCrLf“创建新行,例如签名=”你好,你好吗?“+vbCrLf+”我很好“。会把句子分成两行。
Private Sub createEmail(ByVal toEmailAddresses As String, _
ByVal ccEmailAddresses As String, _
ByVal att1 As String, _
ByVal att2 As String, _
ByVal signature As String, _
ByVal subject As String, _
ByVal displayIt As Boolean)
On Error GoTo foundError
Dim outItem As Outlook.MailItem
Set outItem = Outlook.CreateItem(olMailItem)
outItem.BodyFormat = olFormatHTML
outItem.Recipients.Add toEmailAddresses
outItem.cc = ccEmailAddresses
outItem.subject = subject
If att1 <> "" Then
outItem.Attachments.Add (att1)
End If
If att2 <> "" Then
outItem.Attachments.Add (att2)
End If
outItem.HTMLBody = signature
outItem.Send
'Note: if you wanted to create the email and check it first, use outItem.Save
Exit Sub
foundError:
MsgBox "Error in createEmail: " + CStr(Err) + ", " + Error(Err), vbOKOnly, "ERROR"
End Sub
https://stackoverflow.com/questions/34663617
复制相似问题