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
	
		
			
		
		
	
				
			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: