XL 2016 Code VBA, Sauvegarde PDF un répertoire précis

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

kingfadhel

XLDnaute Impliqué
Je vous propose une code qui permet de sauvegarder sous forme de fichier pdf avec le le nom de l'onglet courant, dans un répertoire précis.
Code:
Private Sub Imprime1PDF()
Application.ScreenUpdating = False
'---Test existence du dossier de sauvegarde---
Call RépertoireExiste("c:\PDFS\")
Call RépertoireExiste("c:\PDFS\" & Year(Date))
Call RépertoireExiste("c:\PDFS\" & Year(Date) & "\RH")

'---Sauvegarde au format PDF dans le dossier ---
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
         "C:\PDFS\" & Year(Date) & "\RH\" & ActiveSheet.Name & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties _
        :=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Application.ScreenUpdating = True
 End Sub

Function RépertoireExiste(Chemin As String) As Boolean
On Error Resume Next
RépertoireExiste = GetAttr(Chemin) And vbDirectory
    If RépertoireExiste = True Then
        Exit Function
    Else
        MkDir (Chemin)
    End If
End Function
 
Bonjour à tous
Ou comme ceci
*Un peu plus court
VB:
Private Sub Imprime1PDF()
Dim Repertoire As String
Application.ScreenUpdating = False
'---Test existence du dossier de sauvegarde---
On Error Resume Next
MkDir "c:\PDFS\"
MkDir "c:\PDFS\" & Year(Date)
Repertoire = "c:\PDFS\" & Year(Date) & "\RH\": MkDir Repertoire
On Error GoTo 0
'---Sauvegarde au format PDF dans le dossier ---
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
Repertoire & ActiveSheet.Name, Quality:=xlQualityStandard, IncludeDocProperties _
:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Application.ScreenUpdating = True
End Sub
 
Dernière édition:
Bonjour à toutes et à tous,

Ou comme cela :
VB:
Option Explicit
Sub PDF_onglet_actif()
    Application.ScreenUpdating = False
    Dim nom As String, où As String
    nom = ActiveSheet.Name
    où = "C:\Users\DoubleZero\Downloads\"    ' adapter
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=où & nom & " - " & Format(Now(), "yyyy mm dd à hh-mm") & ".pdf"
    Application.ScreenUpdating = True
End Sub
A bientôt 🙂
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
3
Affichages
673
Retour