Regueiro
XLDnaute Impliqué
Bonsoir le Forum
Petit problème pour alimenter la 2ème listbox en fonction du choix de la 1ère
Il bute sur chemin ( nothing )
Merci pour votre retour
Petit problème pour alimenter la 2ème listbox en fonction du choix de la 1ère
Il bute sur chemin ( nothing )
Merci pour votre retour
VB:
Option Explicit
'VBA FileSystemObject (FSO)
'Outils - Références - Microsoft Scripting Runtime à activer
Dim FSO As FileSystemObject
Dim MYFILE As File
Dim DOSSIER As Folder
Dim SOUSDOS As Folder
Dim Chemin As Folder
Dim n As Integer
Dim racine As String
Private Sub b_debut_Click()
Set FSO = New Scripting.FileSystemObject
racine = ChoixDossier() ' ou un répertoire C:\xxx e.g.
Set DOSSIER = FSO.GetFolder(racine)
Me.ListBox1.Clear
n = 0
Me.ListBox1.Clear
For Each SOUSDOS In DOSSIER.SubFolders
Me.ListBox1.AddItem SOUSDOS.Name 'DOSSIER.Name
Me.ListBox1.List(n, 1) = SOUSDOS.Path 'DOSSIER.Path
n = n + 1
Next
Me.TextBox1 = DOSSIER.Path
Me.TextBox2 = n & " Dossiers"
End Sub
Private Sub ListBox1_Click()
Dim rép
Dim F1 As Object
rép = Me.ListBox1.Column(1) & "\" & Me.ListBox1
Set FSO = New Scripting.FileSystemObject
Set Chemin = FSO.GetFolder(rép)
Me.ListBox2.Clear
n = 0
On Error Resume Next
'For Each f1 In FSO.GetFolder(MonRepertoire).SubFolders
For Each SOUSDOS In Chemin.SubFolders
Me.ListBox2.AddItem Chemin.Name
Me.ListBox2.List(n, 1) = Chemin.Path
n = n + 1
Next
Me.TextBox1 = Chemin.Path
End Sub
Function ChoixDossier()
If Val(Application.Version) >= 10 Then
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = ActiveWorkbook.Path & "\"
.Show
If .SelectedItems.Count > 0 Then
ChoixDossier = .SelectedItems(1)
Else
ChoixDossier = ""
End If
End With
Else
ChoixDossier = InputBox("Répertoire?")
End If
End Function
Private Sub UserForm_Initialize()
racine = "c:\"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set DOSSIER = FSO.GetFolder(racine)
Me.ListBox1.Clear
Me.ListBox2.Clear
n = 0
For Each SOUSDOS In DOSSIER.SubFolders
Me.ListBox1.AddItem DOSSIER.Name
Me.ListBox1.List(n, 1) = DOSSIER.Path
n = n + 1
Next
Me.TextBox1 = DOSSIER.Path
' listefichiers DOSSIER.Path
End Sub