VBA to Lotus Notes: add attachment IN body

Cleyfe

New Member
Joined
Aug 8, 2016
Messages
2
Hello !

Im beginning to get upset against my computer and I need your help!

I am generating an email from Lotus Notes with VBA. Until now, I am able to create the email, send it and even include an attachment. However, I would like to have the attachment inserted into the body like:

Mail Body

text...

attached file

text...

End of the mail Body

I found only one proposition of solution on internet which is at the link below. However, this solution does not work for me, the line is getting red.

Here is my code at the moment:

Code:
Sub Generate_Mail()

'1) Define recipients
''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim Destinataires As String
Destinataires = Range("Mail").Value
''''''''''''''''''''''''''''''''''''''''''''''''''''''

'2) Open LN session
''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set NSession = CreateObject("Notes.NotesSession")
Set NUIWorkSpace = CreateObject("Notes.NotesUIWorkspace") 'Non indispensable si pas de texte à remplacer dans Body
Set NDatabase = NSession.GetDatabase("", "")

If Not NDatabase.IsOpen Then
    NDatabase.Openmail
End If

Set NDoc = NDatabase.CreateDocument

With NDoc
    .SendTo = Destinataires
    '.CopyTo = Copies
    '.blindcopyto = Destinataires
    .Subject = w_entete

    'Write email text
    .body = Madame_Monsieur & "," & vbNewLine & vbNewLine & _
        Introduction & vbNewLine & vbNewLine & _
        Conclusion & vbNewLine & vbNewLine & vbNewLine '& _
    .Save True, False
End With
''''''''''''''''''''''''''''''''''''''''''''''''''''''


'3) Attachments
''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim FichierProposition As String
Dim FichierProduit(1 To 6) As String
Dim AttachMe As Object
Dim EmbedObj As Object
Dim Import_Export As String


'Define name for attachment file name
Import_Export = Range("Import_Export").Value
If Import_Export = "Neutre" Then
    If Range("Position").Value = Achat Then
        Import_Export = "Importateur"
    Else
        Import_Export = "Exportateur"
    End If
End If


'PDF with attachment
FichierProposition = ThisWorkbook.Path & "\Template_Proposition.pdf"
If FichierProposition <> "" Then
   Set AttachMe = NDoc.CREATERICHTEXTITEM("FichierProposition")
   Set EmbedObj = AttachMe.EmbedObject(1454, "", FichierProposition, "Attachment")
End If


(THIS IS NOT VERY IMPORTANT FOR MY PROBLEM TODAY):
'Term sheet with attached proposition
i = 0   'rétablir compteur à 0
For Each Product In Array("Terme", "Option", "RiskReversal", "TermeActivant", "TermeParticipatif", "RatioMultiterme")
    i = i + 1
    Worksheets(Product).Activate
    If Not Worksheets(Product).Range("B5") = "" Then    'Vérifier s'il y a des lignes remplies concernant le produit
        FichierProduit(i) = ThisWorkbook.Path & "\Fiches_Produit\fiche_" & Product & "_" & Import_Export & "_fr.pdf"
    End If
    If FichierProduit(i) <> "" Then
    Set AttachMe = NDoc.CREATERICHTEXTITEM("FichierProduit(" & i & ")")
    Set EmbedObj = AttachMe.EmbedObject(1454, "", FichierProduit(i), "Attachment")
    End If
Next Product
Worksheets("Intro").Activate
''''''''''''''''''''''''''''''''''''''''''''''''''''''


'4) Allow to open email before sending it:
''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set NUIdoc = NUIWorkSpace.editdocument(True, NDoc)
''''''''''''''''''''''''''''''''''''''''''''''''''''''



'5) Conclude
''''''''''''''''''''''''''''''''''''''''''''''''''''''
Worksheets("Intro").Activate
Range("A1").Activate

'Vider le presse-papier
OpenClipboard (0&)
EmptyClipboard
CloseClipboard
'''''''''''''''''''''''''''''''''''''''''''''''''''''

End Sub


Thanks a lot guys for your help, I hope that I gave enough information!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,216,116
Messages
6,128,930
Members
449,479
Latest member
nana abanyin

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