Control Name when New workbook opened from a template

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
 
D

Dave Peterson

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.
 
G

Gord Dibben

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top