Conditionally delete files by Vba

hdgfss

New Member
Joined
Aug 29, 2019
Messages
41
I have to delete this file But there is a condition
Kill "C:\Users\WolfieeeStyle\Desktop\1.xls"
Kill "C:\Users\WolfieeeStyle\Desktop\2.xls"
Kill "C:\Users\WolfieeeStyle\Desktop\3.xls"


If there is kill.xlsb in this path C:\Users\WolfieeeStyle\Desktop then only kill all that files and if it is not present then dont kill it, do nothing
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi h,
I think this could work, in windows for instance
Code:
Public Sub del123()
  Dim triger As String
  trigerFile = "C:\Users\WolfieeeStyle\Desktop\kill.xlsb"

  If FileExists(trigerFile) Then
      Shell ("del C:\Users\WolfieeeStyle\Desktop\1.xls")
      Shell ("del C:\Users\WolfieeeStyle\Desktop\2.xls")
      Shell ("del C:\Users\WolfieeeStyle\Desktop\3.xls")
  End If
End Sub

Cheers
Sergio
 
Upvote 0
Hi h,
I think this could work, in windows for instance
Code:
Public Sub del123()
  Dim triger As String
  trigerFile = "C:\Users\WolfieeeStyle\Desktop\kill.xlsb"

  If FileExists(trigerFile) Then
      Shell ("del C:\Users\WolfieeeStyle\Desktop\1.xls")
      Shell ("del C:\Users\WolfieeeStyle\Desktop\2.xls")
      Shell ("del C:\Users\WolfieeeStyle\Desktop\3.xls")
  End If
End Sub

Cheers
Sergio

Three errors:

Declared triger but one line later used trigerFile
FileExists: Compile Error, Sub or Function not defined
Shell: Run-time error 53, File not found
 
Upvote 0
Code:
If Dir("C:\Users\WolfieeeStyle\Desktop\kill.xlsb") = "kill.xlsb" Then
  Kill "C:\Users\WolfieeeStyle\Desktop\1.xls"
  Kill "C:\Users\WolfieeeStyle\Desktop\2.xls"
  Kill "C:\Users\WolfieeeStyle\Desktop\3.xls"
End If
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,202
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top