XL 2013 Spécifier le compte courriel à utiliser dans une macro - RÉSOLU

chantalc33

XLDnaute Nouveau
Bonjour à tous,

Je tente de créer un courriel à partir d'un feuille excel (ce que j'arrive à faire sans problème), mais j'ai 2 comptes courriels dans mon outlook et j'aimerais que, par défaut, ce soit le 2e compte qui soit utilisé quand le courriel est créé... Et ça, je n'y arrive pas...

Voici mon code... L'un d'entres vous aurait-il une idée?

Merci!! :)


Sub Create_Mail()

Dim objOutlook As Object
Dim objMail As Object
Dim signature As String
Dim oWB As Workbook
Set oWB = ActiveWorkbook

s = Sheets("LTR-CONDO").Range("T8").Value

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
s, Quality:=xlQualityStandard, IncludeDocProperties _
:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

PDF_File = "P:\my documents\" & s & ".pdf"

If Sheets("LTR-CONDO").Range("AB5").Value = "F" Then

Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)

With objMail

.Display

End With
signature = objMail.HTMLbody
With objMail
.To = ActiveSheet.Range("AB1")
.Subject = ActiveSheet.Range("AC1")
.HTMLbody = "<font face=" & Chr(34) & "Calibri" & Chr(34) & " size=" & Chr(34) & 4 & Chr(34) & ">" & "Cher client," & "<br> <br>" & "Vous trouverez, ci-joint, un document afin d'effectuer la mise-à-jour des protections figurant à votre dossier. Veuillez y porter une attention particulière." & "<br> <br>" & "Merci!" & "<br> <br>" & signature & "</font>"
.Attachments.Add PDF_File
.Save
.Display
End With

Set objOutlook = Nothing
Set objMail = Nothing

Else

Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)

With objMail

.Display

End With
signature = objMail.HTMLbody
With objMail
.To = ActiveSheet.Range("AB1")
.Subject = ActiveSheet.Range("AC1")
.HTMLbody = "<font face=" & Chr(34) & "Calibri" & Chr(34) & " size=" & Chr(34) & 4 & Chr(34) & ">" & "Dear client," & "<br> <br>" & "Attached you will find a document to update the protections on your file. Please pay particular attention to it." & "<br> <br>" & "Thank you!" & "<br> <br>" & signature & "</font>"
.Attachments.Add PDF_File
.Save
.Display
End With

Set objOutlook = Nothing
Set objMail = Nothing

End If
End Sub
 
Dernière édition:

danielco

XLDnaute Accro
Bonjour,

Pour utiliser le compte "XXX@YYY.COM" :

VB:
    Dim C As Object, M As Object, olApp As Object
    Set olApp = CreateObject("Outlook.application")
    Set M = olApp.CreateItem(olMailItem)
    With M
        .Subject = "Subject"
        .Body = "Body"
        .Recipients.Add "test@test.com"
        For Each C In olApp.Session.Accounts
            If C.SmtpAddress = "XXX@YYY.COM" Then
                .SendUsingAccount = C
                Exit For
            End If
        Next C
        .Display
        '.Send
    End With

Cordialement.

Daniel
 

chantalc33

XLDnaute Nouveau
Bonjour Daniel,

Merci pour ta réponse. Malheureusement, ça ne fonctionne pas. Le courriel se génère avec le mauvais compte et s’envoie également avec le mauvais compte. Je n'ai aucun message d'erreur. Et j'ai testé avec ton code sans tenter de l'intégrer au mien, alors je vois pas trop ce qui cloche... :(
 

Discussions similaires

Réponses
6
Affichages
269

Statistiques des forums

Discussions
311 740
Messages
2 082 047
Membres
101 880
dernier inscrit
Anton_2024