VB-envoyer mail automatique depuis Excel vers IBM Notes
Bonjour à tous,
Je vous remercie de prendre le temps de lire mon poste.
Je débute sur VB et après de nombreuses recherches sur différents forums pour trouver la réponse à ma question, j'ai décidé de me lancer :
Grâce à différents sites internet et forums, j'ai pu depuis Excel et VB générer automatiquement un mail avec le fichier .pdf dans le corps du mail ainsi qu'une brève description dans le corps du mail.
Sub EmailPDF()
Const EMBED_ATTACHMENT As Long = 1454
Const stPath As String = ""
MsgBox ("Votre e-mail va être généré.")
Sheets("1234").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ActiveWorkbook.Path & "\" & "XYZ.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
Dim MaDate As String
Dim stFileName As String
Dim vaRecipients As Variant
Dim noSession As Object
Dim noDatabase As Object
Dim noDocument As Object
Dim noEmbedObject As Object
Dim noAttachment As Object
Dim stAttachment As String
Dim vaMsg As Variant
Dim StrSignature As Variant
Dim stSubject As String
On Error GoTo TraiteErreur
stSubject = "Objet du mail"
MaDate = Date
vaMsg = "Bonjour, " & "Cordialement,"
stFileName = "test"
stAttachment = ActiveWorkbook.Path & "\" & "XYZ.PDF"
If Dir(stAttachment) = "" Then GoTo TraitePJ
vaRecipients = "adresse mail destinataire"
Set noSession = CreateObject("Notes.NotesSession")
Set noDatabase = noSession.GetDatabase("", "")
If noDatabase.IsOpen = False Then noDatabase.OPENMAIL
Set noDocument = noDatabase.CreateDocument
Set noAttachment = noDocument.CreateRichTextItem("stAttachment")
Set noEmbedObject = noAttachment.EmbedObject(EMBED_ATTACHMENT, "", stAttachment)
With noDocument
.Form = "Memo"
.sendto = vaRecipients
.Subject = stSubject
.Body = vaMsg
.SaveMessageOnSend = True
.PostedDate = Now()
End With
Dim Workspace
Set Workspace = CreateObject("Notes.NotesUIWorkspace")
Call Workspace.EditDocument(True, noDocument).FieldSetText("Body", vaMsg)
Set noEmbedObject = Nothing
Set noAttachment = Nothing
Set noDocument = Nothing
Set noDatabase = Nothing
Set noSession = Nothing
Exit Sub
TraitePJ:
MsgBox "Un problème est survenu lors de l'insertion de la pièce jointe.", vbCritical, "Error"
Set noEmbedObject = Nothing
Set noAttachment = Nothing
Set noDocument = Nothing
Set noDatabase = Nothing
Set noSession = Nothing
Exit Sub
TraiteErreur:
MsgBox "Un problème est survenu lors de la création du mail", vbCritical, "Error"
Set noEmbedObject = Nothing
Set noAttachment = Nothing
Set noDocument = Nothing
Set noDatabase = Nothing
Set noSession = Nothing
End SubJusqu'ici tout va bien !
J'aimerai pouvoir revoir le formatage du mail : le code que j'utilise crée la structure mail suivante : Fichier joint puis corps du texte.
J'aimerai pouvoir positionner le fichier joint au milieu du texte (après une petite phrase d'introduction).
Est-ce possible ?
Un grand merci pour toutes les idées/conseils que vous pourrez me donner.