|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub del1()
- Dim Fso As FileSystemObject
- Dim oFile As File
- Dim oFolder As Folder
- Dim Str, oRow As Integer
- Dim Sht As Worksheet
- Dim Rng As Range, oRng As Range
- Set Sht = Sheet3
- Set Rng = Sht.Cells(5, 1).CurrentRegion
- ''
- Str = ""
- For ii = 1 To Rng.Rows.Count
- Str = Str & Rng(ii, "D") & ","
- Next ii
- Debug.Print Str
-
- ''Debug.Print Rng.Address
- Set Fso = New FileSystemObject
- Set oFolder = Fso.GetFolder(ThisWorkbook.Path)
- Debug.Print oFolder.Name
- oRow = Rng.Row + Rng.Rows.Count + 10
- For Each oFile In oFolder.Files
- If InStr(Str, oFile.Path) = 0 And InStr(oFile.Name, "l.xlsm") = 0 Then
- 'Debug.Print oFile.Path
- 'oFile.Delete True
- Sht.Cells(oRow, "A") = oFile.Name
- Sht.Cells(oRow, "D") = oFile.Path
- oRow = oRow + 1
- End If
- Next oFile
- Set oRng = Sht.Cells(oRow - 2, "A").CurrentRegion
- Debug.Print oRng.Address, oRng.Row, oRng.Rows.Count
- Stop
- oRng.EntireRow.Select
- Sht.Cells(oRng.Row - 2, "A") = oFolder.Name & "目录共有" & oFolder.Files.Count & "个文件,需要删除文件" & oRng.Rows.Count _
- & oFolder.Name & "目录保留文件:" & Rng.Rows.Count
-
- Stop
- For ii = 1 To oRng.Rows.Count
- Set oFile = Fso.GetFile(oRng(ii, 4))
- Debug.Print oFile.Name, oFile.Path
- oFile.Delete True
- Next ii
- Stop
- oRng.Clear
-
- End Sub
复制代码
|
|