AlanElston

Trashit

Jan 20th, 2021
1,120
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '   https://www.myonlinetraininghub.com/excel-forum/vba-macros/delete-specific-files-in-a-folder
  2. Sub Trashit()
  3. Rem 1 Workbooks info
  4. Const Ext As String = "xlsx"
  5. Const FldrPth As String = "C:\BookData\AR"
  6. 'Dim FldrPth As String: Let FldrPth = ThisWorkbook.path ' can be used if macro is in file in same filder as files to be killded
  7. Dim arrNms() As Variant: Let arrNms() = Array("Sheet2", "DCH") ' <---  This can it be also be got from other lists programatically maybe
  8. Rem 2 Do it
  9. Dim StearIsIt As Variant ' For each of it is in Variant type
  10.    For Each StearIsIt In arrNms()
  11.         If Len(Dir(FldrPth & Application.PathSeparator & StearIsIt & "." & Ext & "", vbNormal)) > 0 Then Kill FldrPth & Application.PathSeparator & StearIsIt & "." & Ext
  12.     Next StearIsIt
  13. End Sub
  14.  
RAW Paste Data