XL 2013 Envoi automatique par Mail (Outlook) d'une feuille de calcul Excel au format PDF

CockerForEver

XLDnaute Nouveau
Bonjour,
Pour construire les plannings par semaine des salariés j'ai fait un fichier Excel que j'utilise depuis des années.
Il me convient bien mais je voudrais le faire évoluer en envoyant en automatique ou semi-automatique les plannings à chaque personne par mail.

J'ai essayé plusieurs macros trouvées sur le net sans succès. (je ne sais plus lesquelles)

Je voudrais envoyer l'onglet Mail au format PDF de la cellule D1:BF24

Est-ce qu'une bonne âme se chargerait de cette partie pour moi ?

Merci. :)
 

Pièces jointes

  • Test Planning .xlsm
    406 KB · Affichages: 5

flc13090

XLDnaute Nouveau
Salut
Je n'ai pas testé
VB:
Sub EnvoyerMail()
'Microsoft Outkook xx.x Object Library
Dim xlWbk As Workbook
Dim xlWsh As Worksheet
Dim rngPlanning As Range
Dim strFilePath As String, strFolder As String, strPdfFile As String
Dim outApp As Outlook.Application
Dim outMail As Outlook.MailItem
Dim outAtt As Outlook.Attachment

Set xlWbk = ThisWorkbook
Set xlWsh = xlWbk.Worksheets("Mail")
Set rngPlanning = xlWsh.Range("D1:BF24")

strFilePath = ActiveWorkbook.Path & Application.PathSeparator
strFolder = "planning\"
strFilePath = strFilePath & strFolder

strPdfFile = Format(Now(), "yyyymmdd") & "_" & "Planning" & "_" & xlWsh.Range("BI6").Value & ".pdf"

rngPlanning.ExportAsFixedFormat Type:=xlTypePDF, _
                                Filename:=strFilePath & strPdfFile, _
                                Quality:=xlQualityStandard, _
                                IncludeDocProperties:=True, _
                                IgnorePrintAreas:=False, _
                                OpenAfterPublish:=False

Debug.Print strFilePath & strPdfFile
Set outApp = New Outlook.Application
Set outMail = outApp.CreateItem(olMailItem)
  
With outMail
    .BodyFormat = olFormatHTML
    .Display
    .HTMLBody = "Bonjour " & xlWsh.Range("BI6").Value & "<br>" & "<br>" & _
                "Vous trouverez votre planning en attache." & "<br>" & "<br>" & _
                "Bonne réception."
    .To = xlWsh.Range("BK5").Value
    .Subject = "Planning de la semaine n° " & xlWsh.Range("V3").Value
    .Attachments.Add strFilePath & strPdfFile
    .Display '.Send
End With

Set outMail = Nothing
Set outApp = Nothing
End Sub
 
Dernière édition:

Discussions similaires

Statistiques des forums

Discussions
312 099
Messages
2 085 269
Membres
102 845
dernier inscrit
Baticle.geo