我需要帮助。我需要删除文件夹中的旧文件。我在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 As String
Dim MyFile As String
Dim cell As Variant
Dim source As Range
MyFolder = Sheets("Delete Revs").Range("K1").Value & "\"
Set source = Range("c3:c8")
For Each cell In source
If cell.Interior.Color = vbRed Then
MyFile = MyFolder & cell.Value
If Dir(MyFile) <> "" Then
Kill MyFile
cell.Interior.Color = vbGreen 'changing the color when file deleted
End If
End If
Next
End Sub