PDA

View Full Version : Solved: I want to go to "File Save As" as soon as openned



kisinana
07-19-2008, 09:26 PM
Is there a way to go to "File Save As" as soon as a file is openned? What I want is as soon as a template is chosen the first thing it does is come back and ask to be saved.
Perhaps a better plan would be to have a macro which would save the file as a date when selected and run as soon as the template was openned?

Bob Phillips
07-20-2008, 02:57 AM
How is the template being opened, via code, or just noram EXcel selection?

And is it reallay a template, an xlt?

kisinana
07-20-2008, 04:41 AM
It is a normal template .xlt. What I have been looking at is when the file is openned it comes up as an xls version of my template. I have put a seperate button on the toolbar for "save as" and then the file name and date can be entered.
What I was looking at doing was changing the "save as" to a small macro that writes the filename with the date and then saves it.
I looked through the archives last night and found a post of yours to do with workbook event code that may be able to perform this. I haven't tried that yet.
Putting it in as workbook event code will it effect other applications?

mdmackillop
07-20-2008, 07:47 AM
Change "Test1" by substituting with "template name1". Save in ThisWorkbook module of your template.


Private Sub Workbook_Open()
If ActiveWorkbook.Name = "Test1" Then
Application.Dialogs(xlDialogSaveAs).Show
End If
End Sub

Bob Phillips
07-20-2008, 08:36 AM
I think you can add the code to the Workbook_Open of the template, with some appropriate checks to ensure it doesn't run a second time. and use GetSaveAsFilename with a pre-loaded name as a prompt.

kisinana
07-20-2008, 02:04 PM
I will try those out tonight. When saving by file name and wanting it to be file name present date, I think I just add ()now to it or ()today?

mdmackillop
07-20-2008, 02:46 PM
You add Date. Formatting as below allows file names to be sorted in date order.


ActiveWorkbook.SaveAs "C:\Test " & Format(Date,"yy-mm-dd") & ".xls"

kisinana
07-20-2008, 11:19 PM
Thanks Guys
For all your help. You have made a bunch of my buddies very happy.
I was able to write most of the code I needed to run this golf scoring program, but you made it possible for the non computer types to now use the program when I am not there.
I may later this fall refine it a little more, but for the rest of the summer we will use what I have written.
We have a Tuesday night hackers and everyone who makes it throws in a couple of dollars. The program randomly pairs golfers and gives a winning order based on their combined scores and entry number. If an odd number play a ghost player is produced with a score that is an average of all who played that night. All this just for the chance at winning a sleeve of balls.
Hi tech for a fun night.
Thanks Kisinana
I will mark this post as solved tomorrow.