1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| Private Sub envoiparmail()
Dim Session As Object
Dim db As Object
Dim doc As Object
Dim rtitem As Object
Dim object As Object
Dim fs As Object
Dim Principaux(2) As String
Dim Copies(3) As String
Dim dir As Object
Dim inti As Integer
Dim passwd As String
On Error GoTo TraiteErreur
' Imprimer
ActiveSheet.PrintOut
'Demande le password Lotus(Dans le cas ou la session necessite un passwd)
passwd = InputBox("Entrer votre password Lotus:", "Password")
' Création de la session Notes
Set Session = CreateObject("Lotus.NOTESSESSION")
'Ouverture d'une session NOTES
Call Session.Initialize(passwd) 'si pas de passwd pas de parametre pour initialize
Set dir = Session.GETDBDIRECTORY("XXXX")
Set db = dir.OpenMailDatabase
' Création d'un document
Set doc = db.CreateDocument
' Création du texte
Set rtitem = doc.CreateRichTextItem("Body")
Call rtitem.AppendText("Bonjour,")
Call rtitem.ADDNEWLINE(3)
Call rtitem.AppendText("Vous trouverez ci-joint,")
Call rtitem.ADDNEWLINE(1)
Call rtitem.AppendText("une demande d'avoir ou une demande de facture supplémentaire.")
Call rtitem.ADDNEWLINE(3)
Call rtitem.AppendText("Sincères salutations.")
Call rtitem.ADDNEWLINE(2)
Call rtitem.AppendText("XXXXXX.")
Call rtitem.ADDNEWLINE(2)
Call rtitem.AppendText("____________________________________________________________________.")
Call rtitem.ADDNEWLINE(2)
Call rtitem.AppendText("Ce message est généré automatiquement.")
Call rtitem.ADDNEWLINE(4)
Call rtitem.AppendText("Le fichier joint : .")
'affectation du type mail
Call doc.APPENDITEMVALUE("Form", "Memo")
Call doc.APPENDITEMVALUE("SendTo", "")
Call doc.APPENDITEMVALUE("CopyTo", "")
Call doc.APPENDITEMVALUE("BlindcopyTo", "XXX@XXXX.com")
Call doc.APPENDITEMVALUE("subject", "Demande d'avoir XXXXXXXX")
'sauvegarde du mail à l envoi
doc.SaveMessageOnSend = True
Dim nom As String
nom = ThisWorkbook.FullName
'Attachement du classeur au mail
Set object = rtitem.embedObject(1454, "", nom, "")
Call doc.Send(False)
Set object = Nothing
Set rtitem = Nothing
Set doc = Nothing
Set db = Nothing
Set Session = Nothing
Exit Sub
TraiteErreur:
MsgBox "Erreur Critique durant l envoi .", vbCritical, "Error"
Set object = Nothing
Set rtitem = Nothing
Set doc = Nothing
Set db = Nothing
Set Session = Nothing
Set fs = Nothing
End Sub |
Partager