After Googling about sending attachment via Lotus Notes, I compiled the code below. Somehow the code cannot be compiled due to "Note error: Cannot write or create file (file or disk is read-only)" and the error points to the line "Call .EmbedObject(1454, "", sFilPath)"
Do I need to import any library or add-in to make it work? Many Thanks!
Do I need to import any library or add-in to make it work? Many Thanks!
Code:
Sub SendLNmail()
Dim nSess As Object
Dim nDb As Object
Dim nDoc As Object
Dim vToList As Variant, vCCList As Variant, vBCCList As Variant, vName As Variant
Dim sFilPath As String
Sheets("Distribution").Select
For i = 1 To Range("A" & Rows.Count).End(xlUp).Row
If Range("A" & i).Value = "Yes" Then
Set nSess = CreateObject("Notes.NotesSession")
Set nDb = nSess.GetDatabase(" ", "mail\username.nsf")
Set nDoc = nDb.CreateDocument()
vToList = Range("B" & i).Value
vCCList = Range("C" & i).Value
vBCCList = Range("D" & i).Value
vName = Range("E" & i).Value
With nDoc
.Form = "Memo"
.Subject = "Test Lotus Notes Email 5.9"
Set nAtt = .CreateRichTextItem("Body")
With nAtt
.appendtext ("Dear " & vName & " ," & vbNewLine & vbNewLine & _
"This is a test email!")
vbAtt = MsgBox("Do you want to attach document?", vbYesNo, "Attach Document")
Select Case vbAtt
Case 6
.appendtext ("********************************************************************")
sFilPath = Application.GetOpenFilename
Call .EmbedObject(1454, "", sFilPath)
Case 7
'Do Nothing
End Select
End With
End With
Call nDoc.ReplaceItemValue("CopyTo", vCCList)
Call nDoc.ReplaceItemValue("BlindCopyTo", vBCCList)
Call nDoc.Send(False, vToList)
End If
Next i
End Sub