Public Sub Notes_Email_Workbook()
Dim recipients As Variant
Dim emailBodyText As String
Dim NewFileName As Variant
'This needs to reflect the correct file location and name
NewFileName = "C:\Documents and Settings\HartG\My Documents\Projects\Sickness\New Macros" & "\" & "Absent-Restriction Procedural documentV3" & ".pdf"
recipients = "Add recipient"
emailBodyText = "Please see attached bla bla bla"
Create_and_Send_Notes_Email "Please see attached bla bla " & Now, recipients, emailBodyText, Array(ThisWorkbook.FullName, NewFileName)
End Sub
Private Sub Create_and_Send_Notes_Email(Subject As String, recipientsArray As Variant, BodyText As String, Attachments As Variant)
Const EMBED_ATTACHMENT As Long = 1454
'Declare objects for Lotus Notes automation
Dim NSession As Object 'NotesSession
Dim NMailDb As Object 'NotesDatabase
Dim NDoc As Object 'NOTESDOCUMENT - the mail document itself
Dim NRichTextItem As Object 'The attachment rich text file object
Dim NEmbeddedObj As Object 'The embedded object (Attachment)
Dim AttachmentsArray As Variant
Dim i As Integer
'Start a Notes session
Set NSession = CreateObject("Notes.NotesSession") 'Lotus Notes Automation Classes (OLE)
Set NMailDb = NSession.GETDATABASE("", "") 'uses the default .nsf database
If Not NMailDb.IsOpen Then
NMailDb.OPENMAIL
End If
'Create a new mail document
Set NDoc = NMailDb.CREATEDOCUMENT
With NDoc
.Form = "Memo"
.SendTo = recipientsArray
.Subject = Subject
.body = BodyText
.SAVEMESSAGEONSEND = True 'Save sent mail?
If TypeName(Attachments) = "String" Then
'Attachments argument is a comma-separated string of filenames
AttachmentsArray = Split(Attachments, ",")
ElseIf TypeName(Attachments) = "Variant()" Then
'Attachments argument is an array of filename strings
AttachmentsArray = Attachments
End If
'For each attachment, create a rich text item with unique name and an associated embedded object
For i = LBound(AttachmentsArray) To UBound(AttachmentsArray)
Set NRichTextItem = .CREATERICHTEXTITEM("Attachment_" & i)
If Dir(AttachmentsArray(i)) <> "" Then
'Function EMBEDOBJECT(TYPE As Integer, CLASS As String, SOURCE As String, [OBJECTNAME])
Set NEmbeddedObj = NRichTextItem.EMBEDOBJECT(EMBED_ATTACHMENT, "", AttachmentsArray(i))
Else
MsgBox "Attachment file not found: " & AttachmentsArray(i)
End If
Next
'Send the document
'SEND(ATTACHFORM As Integer, [RECIPIENTS])
.SEND False
'SAVE(FORCE As Integer, MAKERESPONSE As Integer, [MARKREAD]) As Integer
'MARKREAD: True - the document subject is set to black (read) in the Sent folder; False - red (unread)
.Save True, True, False
End With
'Clean up
Set NMailDb = Nothing
Set NDoc = Nothing
Set NRichTextItem = Nothing
Set NSession = Nothing
Set NEmbeddedObj = Nothing
End Sub