VBA macro to save file, appending Date & Time stamp to filename

roc_on_the_rocks

Board Regular
Joined
Jun 6, 2009
Messages
175
Office Version
  1. 365
Platform
  1. Windows
I have a large Excel file that I need to save frequently, with different revisions. This task would be greatly facilitated if a VBA macro would save the file - to a pre-defined network location - and append current Date and Time stamp to its original filename.

Example:
If the original file name is "Apple.xls", when the macro is called, it would same it as "Apple_2011_04_28_21_27.xls"

Is this someone could help me with?

Any help would be greatly appreciated!

Excel 2007
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
try this:
Code:
Sub SaveIt()
Dim dt As String, wbNam As String

wbNam = "Apple_"
dt = Format(CStr(Now), "yyy_mm_dd_hh_mm")
ActiveWorkbook.SaveAs Filename:= wbNam & dt
End Sub
 
Upvote 0
Solution
I would like to adapt the above code to save to a specific directory and then to close the workbook. Thanks
 
Last edited:
Upvote 0
I to am date stamping and saving,and this work well but how can I save my files to a folder on a network drive. the saved data goes to my documents. I need it to go to a Q drive \company shared\reports.



any advise will be appreciated
 
Upvote 0
I to am date stamping and saving,and this work well but how can I save my files to a folder on a network drive. the saved data goes to my documents. I need it to go to a Q drive \company shared\reports.

any advise will be appreciated


Put the file path (ex: C:\Users\YOURNAMEHERE\Documents\FOLDER1\FOLDER2) into the .SaveAs section of the quote
(File path can be found at the top of the folder window and clicking the downwards arrow at the right of the the box in windows)

Here I have saved the active worksheet into a new workbook in a specific folder into My Documents:

Code:
Worksheets("[B]ACTIVESHEET[/B]").Activate
ActiveSheet.Copy
With ActiveWorkbook
    .SaveAs "C:\Users\[B]YOURNAMEHERE[/B]\Documents\[B]FOLDER1[/B]\[B]FOLDER2[/B]" & [B]FILENAMEHERE[/B] 'Can be a variable
    .Close 0
End With
 
Upvote 0
hi that above code is very helpful to me. i want same to be done but little bit different way. can i save as file from different location without opening file.

For example:
there is 1 file c:\abc\xyz.xls
i want to save as this xyz.xls file with date and time(like xyz_15_01_2018_15:45 PM) from different location (from different xls file) OR is it possible when i close xyz.xls file , it will save as automatically in abc folder

Please guide me. many thanks in advance
 
Upvote 0

Forum statistics

Threads
1,214,830
Messages
6,121,834
Members
449,051
Latest member
excelquestion515

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