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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
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,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

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