Envoyer par VBA 2 feuilles du même fichier
bonjour tout le monde,
je suis un novice des codes VBA , en cherchant a doite a gauche sur internet , j'ai réussi a faire le code ci dessous qui fonctionne mais que je souhaiterai améliorer .
Aujourd'hui ce code permet d'envoyer automatiquement mon onglet actif automatiquement par mail .
Je souhaiterai y ajouter un second onglet " feuille de réserve " + " quitus " mais je n'y arrive pas .
pourriez vous m'aider ?
Je vous en remercie vivement par avance,
Sub ENVOIPDFETS1()
Dim IsCreated As Boolean
Dim i As Long
Dim PdfFile As String, Title As String
Dim OutlApp As Object
' Not sure for what the Title is
Title = Range("A1")
' Define PDF filename
PdfFile = ActiveWorkbook.FullName
i = InStrRev(PdfFile, ".")
If i > 1 Then PdfFile = Left(PdfFile, i - 1)
PdfFile = PdfFile & "_" & ActiveSheet.Name & ".pdf"
' Export activesheet as PDF
With ActiveSheet
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PdfFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With
' Use already open Outlook if possible
On Error Resume Next
Set OutlApp = GetObject(, "Outlook.Application")
If Err Then
Set OutlApp = CreateObject("Outlook.Application")
IsCreated = True
End If
OutlApp.Visible = True
On Error GoTo 0
' Prepare e-mail with PDF attachment
With OutlApp.CreateItem(0)
' Prepare e-mail
.Subject = "-SUIVI DES RESERVES"
.To = Sheets("INFO").[E40].Value & ";"
.CC = Sheets("INFO").[D30].Value & ";" & Sheets("INFO").[D31].Value & ";" & Sheets("INFO").[D32].Value & ";" & Sheets("INFO").[D33].Value & ";" & Sheets("INFO").[D34].Value & ";" & Sheets("INFO").[D35].Value & ";"
' <-- Put email of 'copy to' recipient here Sheets("INFO").[E28].Value & ";"
.Body = "Bonjour," & vbLf & vbLf _
& "Veuillez trouver ci joint la liste des réserves pour l'opération." & vbLf & vbLf _
& "Cordialement," & vbLf _
& Application.UserName & vbLf & vbLf
.Attachments.Add PdfFile
' Try to send
On Error Resume Next
.Send
Application.Visible = True
If Err Then
MsgBox "E-mail was not sent", vbExclamation
Else
MsgBox " : L'E-mail a bien été envoyé a l'entreprise1 ", vbInformation
End If
On Error GoTo 0
End With
' Delete PDF file
Kill PdfFile
' Quit Outlook if it was created by this code
If IsCreated Then OutlApp.Quit
' Release the memory of object variable
Set OutlApp = Nothing