PDA

View Full Version : Solved: Saves workbook as todays date?



Paul C
07-05-2006, 01:14 AM
Hi is there a way to designate a workbook a default savename? todays date for example?

Thanks

ALe
07-05-2006, 01:49 AM
explain what are you trying to do

OBP
07-05-2006, 02:03 AM
The answer to your question is yes. It will save a new workbook each time it saves with the addition of todays data in the title. The date cannot be in the 00/00/000 as the "/" is not allowed in the file name.
The code to add the date to the end of the file name looks like this.

newname = "Your File name & Path goes here" & Right(Date, 2) & Mid(Date, 4, 2) & Left(Date, 2) & ".xls"
ActiveWorkbook.SaveAs Filename:=newname, FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False

Paul C
07-05-2006, 02:36 AM
Sorry for not making much sense ALe, Its a bad habit of mine, What i would like to do is have the workbook save with a automatic name of my choice, it would be a bonus if i could include the date as part of the save name, example Register_5_11_06.xls

Hope that makes a bit more sense, Thanks for the code OBP , where does that need to be placed? I'm still trying to get to grips with it all :)

ALe
07-05-2006, 02:46 AM
see the file

OBP
07-05-2006, 03:10 AM
I haven't looked at ALe's file, but the code would normally go on a "Save" command button.

Paul C
07-05-2006, 03:12 AM
see the file

Works great ALe, but i get a error if i cancel the save, anyway of stopping this?

I'll have to start paying you soon :rofl:

ALe
07-05-2006, 03:16 AM
Private Sub CommandButton4_Click()
newpath = ThisWorkbook.Path 'put here the path you want
newname = newpath & "\Register_" & Right(Date, 2) & Mid(Date, 4, 2) & Left(Date, 2) & ".xls"
On Error GoTo fine
ActiveWorkbook.SaveAs Filename:=newname
fine:
End Sub

Paul C
07-05-2006, 03:25 AM
Works great many thanks ALe and OBP, I'll try to leave you in peace now :)

well for a while at least

ALe
07-05-2006, 03:33 AM
Paul I suggest you read a vba guide. Of course you're welcome if you have any question. It's just I think that if you gain some basics you'll be able to learn vba in a faster way and adapt our codes to your needs.

Bye

Paul C
07-05-2006, 03:51 AM
Paul I suggest you read a vba guide. Of course you're welcome if you have any question. It's just I think that if you gain some basics you'll be able to learn vba in a faster way and adapt our codes to your needs.

Bye

Will do ALe, I have a good understanding of excel, access ect, I have never messed with any sort of programming, but would love to start learning. can you recommend any good beginner sites?

ALe
07-05-2006, 04:03 AM
a first small handbook here
http://msdn.microsoft.com/archive/en...ml/web/004.asp

a book by the best vba guru
Excel Power Programming With VBA (http://www.vbaexpress.com/forum/Excel Power Programming With VBA)

you can find a lot of handbooks on internet. they should be OK to start to understand the structure and the objects of VBA

Paul C
07-05-2006, 07:37 AM
Thanks a lot ALe, I give them a go.