Hi,
I have one excel file with file name in one column and its folder path in other column. I want to delete the files from the excel sheet through vba.
Hi,
I have one excel file with file name in one column and its folder path in other column. I want to delete the files from the excel sheet through vba.
According to your attachment a VBA demonstration as a starting point :
PHP Code:
Sub Demo1()
Dim Bill, N&
With Sheet3
For Each Bill In .Evaluate(Replace("C2:C#&B2:B#", "#", .UsedRange.Rows.Count))
If Dir(Bill) > "" Then Kill Bill: N = N + 1
Next
End With
MsgBox "Deletion # : " & N
End Sub
► Do you like it ? ► ► So thanks to click on bottom left star icon « ★ Add Reputation » ! ◄ ◄
Dear Marc L
The above code shows a run-time error '52': Bad file name or number. I need to delete each files in column be which is located at column D folder path. the vba shall run even if there is any error (for example, if the file doesn't exist).
As you must see in the code it checks first if the file exists and as it well works with 'normal' files …
Hi Marc L,
The files are existing, still it shows the error.
Also, "sheet3" is not the actual sheet name, should I change the same with the actual sheet name where the data lies?
As I wrote « According to your attachment » Sheet3 is the codename of the Delete List worksheet
but « as a starting point » you are free to amend the procedure per your will.
Check the attributes of the file …
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks