Save CSV into year/month folder, create folder if does not exist

Aviles

Board Regular
Joined
Dec 17, 2008
Messages
163
Hello,

I am currently using the below code which saves a CSV into the chosen file path:

VBA Code:
Sheets("InputFile").Select
    Sheets("InputFile").Copy
    
    Dim Name As String
    Name = Format(Now(), "DDMMYY HHMM")
    ChDir _
        "S:\FM\Folder1\Folder2\Folder3"
        ActiveWorkbook.SaveAs Filename:= _
        "S:\FM\Folder1\Folder2\Folder3\Upload " & Name & ".csv" _
        , FileFormat:=xlCSV, CreateBackup:=False
        
    ActiveWorkbook.Close SaveChanges:=True

I would like for the CSV file to automatically save to the correct Year and Month folder within this path. And if the current Year/Month folder does not exist, I would like to automatically add it.

Can anyone help me with this please?

Thanks.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,212,933
Messages
6,110,752
Members
448,295
Latest member
Uzair Tahir Khan

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