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

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
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,504
Messages
6,114,020
Members
448,543
Latest member
MartinLarkin

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