Send Attachment via Lotus Notes using VBA

kwlai

New Member
Joined
Aug 4, 2014
Messages
2
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!

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
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,216,110
Messages
6,128,890
Members
449,477
Latest member
panjongshing

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top