excel - 如何删除文件夹中B列和红色的文件
问题描述
我需要帮助。我需要删除文件夹中的旧文件。我在 B 列中有一个文件列表,旧文件的颜色为 RGB(255,0,0)。假设代码将如下所示:
Dim MyFolder As String
Dim MyFile As String
Dim cell As Variant
Dim source As Range
Set source = Range("c3:c8")
MyFolder = Sheets("Delete Revs").Range("K1").Value & "\"
MyFile = Dir(MyFolder & "\" & "*.*")
For Each cell In source
If cell.Interior.Color = RGB(255, 0, 0) Then
Kill MyFile
Else
End If
Next
解决方案
Sub DeleteFiles()
Dim myFolder, myFile As String
Dim Cel As Variant
myFolder = Sheet1.[A1] & "\" 'Folder Path
'Looping for Visible Cells Only
For Each Cel In Sheet1.Range("C3:C8").SpecialCells(xlCellTypeVisible)
myFile = myFolder & Cel 'File Path
If Cel.Interior.Color = vbRed Then
If Len(Dir$(myFile)) > 0 Then 'If File Exits in Folder
Kill (myFile) 'Delete File
End If
End If
Next Cel
End Sub
推荐阅读
- r - 如何在ggplot的同一个图例方框中绘制填充颜色和alpha混合颜色
- java - 如何以编程方式创建 CardView
- ios - iOS蓝牙配对对话框被dispatch_sync调用“吃掉”
- java - 返回的 REST 标准(创建和更新)是什么?
- pandas - 熊猫数据框合并不同级别之间的合并可能会产生意想不到的结果
- ios - ObservableObject 不更新视图
- python - 如何在python中抑制ITK警告消息
- c++ - 程序和Shell之间的字符串加密结果不一致
- sql-server - 是否有任何 SQL 代码可以删除每个客户代码的重叠连续日期跨度?
- django - POSTMAN -> DJANGO -- 上传二进制文件 (jpeg)。无论我做什么都无法让它工作