Bonjour,
Je ne suis pas expert en vba néanmoins je peux vous confirmer que ceci est possible.
Vous trouverez ci dessous un exemple de macro que j'utilise.
Celle ci me permettant l'envoi d'un fichier Excel converti en .pdf et nécessitant un mot de passe déclencher la macro d'envoi, elle permet également de conserver le fichier pdf dans un répertoire de sauvegarde.
Attention, a bien activer Microsoft Outlook 1x Object Library sinon celle ci ne fonctionnera pas.
Bon courage à vous
Sub SendWithMail()
Dim Mdp As String
Mdp = Application.InputBox("Veuillez introduire votre mot de passe")
If Mdp <> "TEST" Then MsgBox "Accès refusé !": Exit Sub
' Nécessite la référence : Microsoft Outlook 1x Object Library
Dim olApp As Outlook.Application
Dim olMail As MailItem
Dim CurFile As String
Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)
' "C:\Users\Thierry\AppData\Local\Temp\MaFeuille.pdf "
CurFile = ThisWorkbook.Path & "\" & "TEST.pdf"
ThisWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:=CurFile, _
Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
With olMail
.To = "
test@test.fr"
.CC = ""
.Subject = "#" & Range("Client!H1").Value & "#" & "TEST" & " " & Range("essai!B3").Value & " " & Range("Client!D3").Value
.Body = "Bonjour," & vbNewLine & vbNewLine & _
"Vous trouverez ci-joint le fichier PDF" & vbNewLine & vbNewLine & _
"Cordialement"
.Attachments.Add CurFile
'.Attachments.Add "c:\My Documents\book.doc"
.Display '.Send
End With
MsgBox "Merci de vérifier que le message apparait dans -messages envoyés- dans votre messagerie OUTLOOK."
1
' Effacer les variables objets
Set olMail = Nothing
Set olApp = Nothing
Do While fich <> ""
Loop
Kill ActiveWorkbook.Path & "\" & "*.pdf" ' Là ou détruit le fichier créé
Dim Nomfichier$, DestinationFile$
Nomfichier = ThisWorkbook.FullName
DestinationFile = "C:\TEST\Sauvegarde\"
ThisWorkbook.SaveAs (DestinationFile & ThisWorkbook.Name)
Kill Nomfichier
End Sub