vba to kill file and folders in it with names created by vba

Charleton

New Member
Joined
Aug 30, 2017
Messages
23
I have a .xlsm with the following code:

VBA Code:
Dim strDir As String
    
    strDir = "C:\AUDITS\PROCESS\" & CurrentYear & "\" & currentmonth & "\" & Format$(Date, "mm-dd-yyyy")

This folder holds files related to a daily process, but they only need to be kept the rest of the day. I would like to make a macro to purges the Directory created by "Current Year" and all subdirectories and files.

So in the case of 2020, I want it to kill C:\AUDITS\PROCESS\2020\*

It would be best if this "killed" them instead of just sending them to the recycle bin.

I can not find a way to get excel to do this, based on the code where the subdirectory is created by the Current Year function. It works if I directly make it 2020, but it needs to shift from year to year.

I hope this makes sense, but I cannot figure out how to get it to work.

Thanks in advance for any help!
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Thanks, this is pretty much what I was trying. The issue is likely with nesting quotes in the kill command which I am building with a variable to define part of the filepath. How do I get:

VBA Code:
Kill "C:\AUDITS\PROCESS\" & CurrentYear & "\*.*"

to read as

VBA Code:
  Kill "C:\AUDITS\PROCESS\2020\*.*"

but where 2020 will be determined by CurrentYear which has a value of Year(Date)
 
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