如何删除B列和红色文件夹中的文件

问题描述 投票:0回答:1

我需要帮助。我需要删除文件夹中的旧文件。我在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
excel vba for-loop delete-file
1个回答
0
投票
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
© www.soinside.com 2019 - 2024. All rights reserved.