Save files as date & time by default! This may be simple and I'm trying to figure out myself too..

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
When i save the WORKBOOK's name by default it save as BOOK1, but I want it to be today's (=now) date and time instead on Book1...Is that possible...

I check the options the can't seems to locate it:biggrin:


Please help thanks!
Ped:)
 
Last edited:
Sorry VoG, I was cross posting ....

When i run the code
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Not SaveAsUI Then
    Cancel = True
    Application.EnableEvents = False
    ActiveWorkbook.SaveAs Filename[B][COLOR=red]:[/COLOR][/B]=Format(Now, "dd-mm-yyyy hh-mm-ss")
    Application.EnableEvents = True
End If
End Sub
it is showing Runtime error '1004' Vb project and XLM sheets cannot be saved in macro free workbook, but it is my default settigng to save any workbook in "Mecro enabled"....:confused:

I want no new file to be created when i click on save and close. I want this to happen only when i save as new file...is that possible???

Thanks again VoG!
 
Upvote 0
That is strange because for me it saved as an xlsm file. Anyway, that was slapdash coding :oops:.

Try this - it will save as the current date and time only when you Save As.

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI Then
    Cancel = True
    Application.EnableEvents = False
    ActiveWorkbook.SaveAs Filename:=Format(Now, "dd-mm-yyyy hh-mmss") & ".xlsm"
    Application.EnableEvents = True
End If
End Sub
 
Upvote 0
Now when i open a new workbook and then close it ask
'Do you want to save?'
I click on Yes
And it saved as Book1 not time and date and no error message...
 
Upvote 0
I am baffled :confused:

This works but it prompts twice :eeek: despite several ways of trying to stop that from happening.

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If ActiveWorkbook.Saved Then
    Cancel = True
    Exit Sub
End If
If SaveAsUI Or InStr(Me.Name, ".") = 0 Then
    Cancel = True
    Application.EnableEvents = False
    ActiveWorkbook.SaveAs Filename:=Format(Now, "dd-mm-yyyy hh-mm-ss") & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
    Application.EnableEvents = True
    ActiveWorkbook.Saved = True
End If
End Sub
 
Upvote 0
Vog! I understand u're baffled...:biggrin:

Code:
If SaveAsUI Or InStr(Me.Name, ".") = 0 Then

this code is not giving any error mesage...
When I save as it is prompting 2wice which is okay but when click yes..it

saved the file name as Book1
:)
 
Upvote 0
I created a new workbook, entered some data then clicked the X, clicked Yes to save the file then Cancel for the second prompt. It saved the file as the date & time. I then used Save As and again it saved as date and time with no prompts.
 
Upvote 0
Vog, Great....!

Thank you so much again;)

I'm sure i got you tight up just for this thread...! THanks for helping and making me understand how things worked....


Good Day!!!
 
Upvote 0
You are welcome :)

I just cannot understand why it prompts twice. But it is good practice to save before closing - it is too easy to click the wrong button and lose a lot of work.
 
Upvote 0
I am not going to use this untill I become very familiar with how it works...prompting is fine with me...that is okay..

You're great....!

Thanks again!
 
Upvote 0

Forum statistics

Threads
1,226,870
Messages
6,193,439
Members
453,799
Latest member
shanley ducker

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