Control Name when New workbook opened from a template

  • Thread starter Thread starter SC in Texas
  • Start date Start date
S

SC in Texas

How can I control the name of a new workbook opened from template?
Such as using MyWorkbook.xlt to open MyWorkBookToday.xls instead of
MyWorkbook1.xls.

Thanks,
Steve
 
The name of the file (including the extension) is set when you (or the user)
saves the file.

I don't think you can control how excel names workbooks that are created based
on template files.

Well, you could provide a macro that creates the file and then saves the file
with the name (and location) you want.
 
It can be done but what if you open the Template more than once per day?

This code placed in Thisworkbook module of MyBook.xlt will immediately save
the copy as mybookmm-dd-yyyy.xls but if a copy with that name already exists
what do you want to do?

Private Sub Workbook_Open()

If ActiveWorkbook.Path <> "" Then Exit Sub
'allows you to open a saved copy without renaming

'names and saves newly opened copy
ActiveWorkbook.SaveAs Filename:= _
"C:\Program Files\Microsoft Office\Exceldata\mybook" & _
Format(Date, "mm-dd-yyyy") & ".xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False _
, CreateBackup:=False

End Sub


Gord Dibben MS Excel MVP
 
Back
Top