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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| Option Explicit
Dim cpt As Long
Private Sub DecompteA()
Dim LastRow As Long, i As Long
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
cpt = 0
With ShParam
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
For i = LastRow To RDepart Step -1
If FSO.fileExists(.Cells(1, 1) & "\" & .Cells(i, 2)) Then
If UCase$(.Cells(i, 1)) = "X" Then cpt = cpt + 1
Else
.Cells(i, 1) = "o"
End If
Next i
End With
Set FSO = Nothing
End Sub
Private Sub DelSheet(sFichier As String)
Dim Wsh As Object, Wkb As Workbook
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set Wkb = Workbooks.Open(Filename:=sFichier)
For Each Wsh In Wkb.Worksheets
On Error Resume Next
If Wsh.Visible = xlHidden Then Wsh.Delete
If Wsh.Visible = xlVeryHidden Then
Wsh.Visible = True
Wsh.Delete
End If
On Error GoTo 0
Next Wsh
Wkb.Close True
Set Wsh = Nothing
Set Wkb = Nothing
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Sub Lecture()
Dim i As Long
Dim LastRow As Long
Dim sDossier As String, sFichier As String
Application.StatusBar = ""
LastRow = ShParam.Range("B" & Rows.Count).End(xlUp).Row
DecompteA
If cpt = 0 Then
MsgBox "Taper dans la colonne A un x ou X en vis à vis" & vbCrLf & _
"des fichiers à traiter de la colonne B", vbInformation + vbOKOnly, "x ou X"
Exit Sub
End If
sDossier = ShParam.Cells(1, 1)
For i = RDepart To LastRow
sFichier = sDossier & "\" & ShParam.Cells(i, 2)
If UCase$(ShParam.Cells(i, 1)) = "X" Then
DelSheet sFichier
End If
Application.StatusBar = i - RDepart + 1
Next i
Application.StatusBar = "Terminé"
End Sub |
Partager