Help using variable in KILL command file path

PatrickSchmidt

New Member
Joined
Apr 30, 2014
Messages
25
Hello,
I made a macro to save a file with todays date in a folder. I'll be doing this everyday and I don't want the folder to fill with workbooks. I would like to keep yesterdays and delete the file dated the day before yesterday.
Also If anyone can give me a tip for adding in holidays to the workday function I'd really appreciate it.
Any help is greatly appreciated. Thank you!
Excel 2010
my variables and code that are not working:

Sub CleanUp()


Dim TwoDays
TwoDays = Format(WorksheetFunction.<wbr>WorkDay(Date, -2), "yyyy mm-dd")

Kill "C:\Test\ & TwoDays & TheRestOfFileName.xlsx"


End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
you are going to need to create a list of holidays depeing on the relevant Country, excel only understands weekends, the optional argument (holidays) needs to be a list given by the user
 
Upvote 0
And for the first question try:

Rich (BB code):
Dim TwoDays as String

Rich (BB code):
Kill "C:\Test\" & TwoDays & "TheRestOfFileName.xlsx"

 
Upvote 0

Forum statistics

Threads
1,215,461
Messages
6,124,955
Members
449,199
Latest member
Riley Johnson

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