Linux Driver

2016年1月8日 星期五

[Access VBA] Send Email from Access VBA

Private Sub Command0_Click()

Dim olApp As Object
Dim objMail As Object

On Error Resume Next 'Keep going if there is an error

Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open

If Err Then 'Outlook is not open
Set olApp = CreateObject("Outlook.Application") 'Create a new instance of Outlook
End If

'Create e-mail item
Set objMail = olApp.CreateItem(olMailItem)

With objMail

'Set body format to HTML
.BodyFormat = olFormatHTML

.To = "your email; your second email"
.Subject = "Subject"
.HTMLBody = "<HTML><H2>The body of this message will appear in HTML.</H2><BODY>Type the message text here. </BODY></HTML>"
'.Send     ' 直接寄出
.Display  ' 顯示outlook

End With


沒有留言 :