Publipostage via Excel

Bonjour tout le monde,

J'ai besoin d'aide svp pour combiner 2 codes VBA que j'ai trouvés sur internet (je n'ai pas de connaissance en VBA).

Le code est pour faire du publipostage via une liste Excel.

Le code fonctionne bien, mais je voudrais insérer un autre code pour choisir l'adresse Outlook utilisée pour l'envoie.

Voici le code :

Option Explicit
Private OL_App As Object
Private OL_Mail As Object
Private sSubject As String, sBody As String

Sub SendDocuments()
' Generate e-mails to be sent to a list of mail recipients, with a customized attachment and message for each person

Dim i As Long
Dim tabContactNames As Variant, tabContactEmails As Variant, tabFNames As Variant

' Init
Application.ScreenUpdating = False
' Open Outlook
On Error Resume Next
Set OL_App = GetObject(, "Outlook.Application")
If OL_App Is Nothing Then
Set OL_App = CreateObject("Outlook.Application")
End If
On Error GoTo 0
' Read E-mail parameters
sSubject = Range("C6").Value
sBody = Range("C8").Value
' Read Contact list
tabContactNames = Range("C16:C25").Value
tabContactEmails = Range("D16:D25").Value
tabFNames = Range("E16:E25").Value
' Generate e-mails
For i = 1 To UBound(tabContactNames, 1)
If tabContactNames(i, 1) <> vbNullString Then
Call CreateNewMessage(tabContactNames(i, 1), tabContactEmails(i, 1), tabFNames(i, 1))
End If
Next i

MsgBox "The process has been entirely completed."

Set OL_App = Nothing
Set OL_Mail = Nothing
Application.ScreenUpdating = True

End Sub

Private Sub CreateNewMessage(strContactName, strContactTo, strFName)
' Create a new message with the following inputs :

Set OL_Mail = OL_App.CreateItem(0)
With OL_Mail

 .To = strContactTo
 '.CC = "alias1@domain1.com"
 '.BCC = "alias2@domain1.com"

 .Subject = sSubject
 .Body = sBody
 .BodyFormat = 1 'Format : 0=undetermined; 1=plain text; 2= HTML; 3=rich text
 .Importance = 2 'Importance : 0=low; 1=normal; 2= high
 .Sensitivity = 3 'Confidentiality : 0=normal; 1=personal; 2=private; 3=confidential
 .Attachments.Add (strFName)

' Display or send the message
 .Display
 '.Send
End With

Set OL_Mail = Nothing
End Sub

Et voici ce que je veux insérer dans le code précédent (toute autre proposition qui fait l'affaire est la bienvenue) :

Dim CompteOutlook As Account

For Each CompteOutlook In oOutlook.Session.Accounts
    If CompteOutlook.SmtpAddress = "MonNom@mon-email.fr" Then ' <-- modifiez l'adresse
        .SendUsingAccount = CompteOutlook
        Exit For
    End If
Next CompteOutlook

Enfin, j'aimerai aussi pouvoir insérer automatiquement ma signature enregistrée par défaut, si possible.

Merci beaucoup pour votre aide.

Bonne jounnée!

Anas.

Rechercher des sujets similaires à "publipostage via"