Dim Liste() As String
Sub ChercherRépertoire()
Dim a As Integer
a = 0
'INDIQUER LE CHEMIN DU REPERTOIRE
MyPath = "C:\"
MyName = Dir(MyPath, vbDirectory)
Do While MyName <> ""
' Ignore le répertoire courant et le répertoire contenant le répertoire courant
If MyName <> "." And MyName <> ".." Then
' Utilise une comparaison au niveau du bit pour vérifier que MyName est un répertoire.
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
ReDim Preserve Liste(a)
Liste(a) = MyName
a = a + 1
End If '
End If
MyName = Dir ' Extrait l'entrée suivante
Loop
End Sub
Private Sub CommandButton1_Click()
Répertoire = MyPath & ListBox1.Text & "\"
Fic = Répertoire & "CDE N° " & Cells(11, 12) & " - " & Cells(11, 14) & ".xlsm"
FichierCible = Application.GetSaveAsFilename(Fic, Filefilter:="Classeur Excel (*.xlsm), *.xlsm")
'POUR ENREGISTRER LE FICHIER AU FORMAT PDF
FicPdf = Répertoire & "CDE N°" & Cells(11, 12) & " - " & Cells(11, 14) & ".pdf"
If FichierCible <> False Then
ActiveWorkbook.SaveAs FichierCible
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
FicPdf, Quality:=xlQualityStandard, IncludeDocProperties:= _
True, IgnoredPrinAreas:=False, OpenAfterPublish:=False
MsgBox "Le fichier a été enregistré sous " & FichierCible
End If
Unload Me
End Sub
Private Sub UserForm_Initialize()
Call ChercherRépertoire
ListBox1.List = Liste
End Sub