VBA to Save File in Todays Date

thardin

Board Regular
Joined
Sep 29, 2021
Messages
137
Office Version
  1. 365
Platform
  1. Windows
Hello,
I'm trying to save a file at work on a daily basis in a folder and I want to use VBA.
However, the date in the file name changes daily and there are subfolders for every month and another subfolder for everyday.

The path where I want to save is:
\\nfpgshare-1.ed.com\export\shareholder_acc\629\629 Share Class\Name\Trade\2021

the subfolder would be 01-January, 02-February, etc

The title of the document would be "629 Shares TD mm.dd.yy"

Please include explanations so I can do this in different scenarios, such as if there was a daily folder within the monthly folder.
Thank you
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Here is a macro that could work for you. Just update the save directory (currently saves to user profile's desktop) and file format type that you need and you should be all set.

VBA Code:
Sub SaveFile()

    Dim NameFile As String

    Range("CW1") = Month(Date)
    Range("CX1") = Day(Date)
    Range("CY1") = Year(Date)
    Range("A1").Select
   
    With Worksheets("[U]ENTER WORKSHEET NAME HERE[/U]")
        NameFile = "629 Shares TD " & .Range("CW1") & "." & .Range("CX1") & "." & .Range("CY1") & ".xlsm"
    End With
    NameFile = Application.GetSaveAsFilename(InitialFileName:=Environ("USERPROFILE") & "\Desktop\" & NameFile, FileFilter:="Excel Macro-Enabled Workbook (*.xlsm),*.xlsm")
    If fileSaveName <> "False" Then
        ActiveWorkbook.SaveAs Filename:=NameFile, FileFormat:=52
    End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,449
Members
449,083
Latest member
Ava19

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