2,462
社区成员
发帖
与我相关
我的任务
分享
https://blog.csdn.net/ljr_123/article/details/113858925
Sub 删除目标文件()
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim root_path '根文件夹路径
'root_path = "D:\工作\数据类" '根文件夹路径。假设所有文件在 “D:\工作\数据类” 文件夹中
root_path = InputBox("请输入文件所在文件夹的完整路径!" & _
Chr(10) & Chr(10) & "例如:" & Chr(10) & "文件夹所在路径为 “D:\工作\数据类”," & "则输入" & _
Chr(10) & "“D:\工作\数据类”")
Dim cnt%
cnt = Cells(Rows.Count, "a").End(xlUp).Row
Dim arr_AB As Variant
arr_AB = Range("a1", Cells(cnt, "b")) '数据从“A列”第一行开始
Dim file_name$, file_path$
For i = 1 To cnt
file_name = Trim(arr_AB(i, 2)) & "_" & WorksheetFunction.Substitute(Trim(arr_AB(i, 1)), ".", "_")
file_path = root_path & "\" & file_name
file_path = "D:\工作\数据类\06进销存\02进销存生成\2020\01进销存_从平台下载数据\7月\最终\202007进销存.xlsx"
'如果文件存在则删除
If fso.FileExists(file_path) Then
fso.DeleteFile file_path
End If
Next
End Sub