Private Sub CommandButton1_Click()
With ActiveWorkbook
Application.DisplayAlerts = 0
.SaveAs FileName:="C:\Users\JCGL\Downloads\" & Feuil5.Cells(7, 2) & ".xls" ' à modifier
Application.DisplayAlerts = 1
' Envoyer le mail via la fonction
SendNotesMail "LeSujet", "LeChemin+LeFichier", "romain.g@fai.fr", "Le texte", False
End With
End Sub
Function SendNotesMail(Subject As String, attachment As String, _
recipient As String, bodytext As String, SaveIt As Boolean) As Boolean
Dim Maildb As Object
Dim UserName As String
Dim MailDbName As String
Dim MailDoc As Object
Dim AttachME As Object
Dim session As Object
Dim EmbedObj As Object
On Error GoTo err_SendNotesMail
'Start a session to notes
Set session = CreateObject("Notes.NotesSession")
'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string
UserName = session.UserName
MailDbName = Mid$(UserName, 4, 1) & _
Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
'Open the mail database in notes
Set Maildb = session.GETDATABASE("", MailDbName)
If Maildb.IsOpen = True Then
'Already open for mail
Else
Maildb.OpenMail
End If
'Set up the new mail document
Set MailDoc = Maildb.CreateDocument
MailDoc.Form = "Memo"
MailDoc.sendTo = recipient
MailDoc.Subject = Subject
MailDoc.Body = bodytext
MailDoc.SaveMessageOnSend = SaveIt
'Set up the embedded object and attachment and attach it
If attachment <> "" And Dir(attachment) <> "" Then
Set AttachME = MailDoc.CreateRichTextItem("Attachment")
Set EmbedObj = AttachME.EmbedObject(1454, "", attachment, "Attachment")
'MailDoc.CREATERICHTEXTITEM ("Attachment")
End If
'Send the document
MailDoc.Send 0, recipient
Maildb.Close
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set session = Nothing
Set EmbedObj = Nothing
SendNotesMail = True
end_SendNotesMail:
Exit Function
err_SendNotesMail:
Select Case Err.Number
Case 429:
MsgBox "Error: " & vbCrLf & Err.Description & vbCrLf & _
"Possible cause : " & vbCrLf & "Lotus Notes not installed", _
vbCritical, "Error while initializing LotusNotes"
Case Else:
MsgBox Err.Description & Err.Number, vbCritical, "Error Lotus Notes Mail"
End Select
Resume end_SendNotesMail
End Function