1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| 'Creation avec DIR et MKDIR
Private Sub CommandButton1_Click()
Dim I&, cel As Range, cheminsub$, sheminsubsub$, racine$
' creation du dossier maitre seulement si il n'existe pas
racine = Environ("userprofile") & "\DeskTop\on board"
If Dir(racine, vbDirectory) = "" Then MkDir (racine)
'creation des sous dossiers du maitre colonne "A"
finA = Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
With Sheets(1)
For I = 1 To finA
If .Cells(I, 1) <> "" Then
cheminsub = (racine) & "\" & Cells(I, 1).Text
If Dir(cheminsub, vbDirectory) = "" Then MkDir cheminsub
End If
Next
'creation des sous sous dossiers du client colonne "B"
finb = Sheets(1).Cells(Rows.Count, 2).End(xlUp).Row
For I = 1 To finb
If .Cells(I, 2) <> "" Then
Set cel = .Range(.Cells(I, 1), .Cells(1, 1)).Find("*", lookat:=xlWhole, SearchDirection:=xlPrevious)
cheminsubsub = racine & "\" & cel.Text & "\" & Cells(I, 2).Text
'MsgBox .Cells(i, 2).Address & cel.Address
If Dir(cheminsubsub, vbDirectory) = "" Then MkDir cheminsubsub
End If
Next
'creation des sous sous sous dossiers du sous dossier du dossier client colonne "C"
finc = Sheets(1).Cells(Rows.Count, 2).End(xlUp).Row
For I = 1 To finc
If .Cells(I, 3) <> "" Then
Set cel = .Range(.Cells(I, 2), .Cells(1, 2)).Find("*", lookat:=xlWhole, SearchDirection:=xlPrevious)
Set cel1 = .Range(.Cells(I, 1), .Cells(1, 1)).Find("*", lookat:=xlWhole, SearchDirection:=xlPrevious)
MsgBox cel1 & "\" & cel & "\" & .Cells(I, 3)
End If
Next
End With
End Sub |
Partager