Saving to a different name

craigwojo

Board Regular
Joined
Jan 7, 2005
Messages
218
Hi everyone,

I have a button that I would like to put a macro on. The macro should be able to do the following:

Save the name of the file as the current date & time and put the file in the "My Documents" folder. ie. the file would be saved in the My Documents folder as 2006Sept22_10.10.40.xls.

Thank you,
Craig
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,808
Office Version
  1. 365
Platform
  1. Windows
Hi Craig,

Firstly you cannot include ":" as part of the file name, that character isn't accepted. So I've removed it from the file name generator. You may also need to change the file path location in the Filename:= bit. Code as follows:

Code:
Sub Temp()

Dim flName As String

    flName = Format(Now, "yyyymmmdd_hhmmss") & ".xls"

ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings\My Documents\" & flName

End Sub

To assign to a button go to View->Toolbars->Forms. Place a command button on the sheet, right click it and assign it this macro.

Hope this helps.

:)
 

Forum statistics

Threads
1,136,269
Messages
5,674,743
Members
419,525
Latest member
helensesc

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
Top