File name

  • Thread starter Thread starter Rpettis31
  • Start date Start date
R

Rpettis31

I have a template which users can save as etc. I would like to know how I
can get the name of the file. The workbook has an auto open and asks if you
would like to update the file. I only want this to appear in the template.

So if I were to open myfile.xls the autoopen would be
If currentworkbook filename <> mytemplate then exit.

Not sure of how I obtain the filename.
 
If the template file was used to create a new workbook, not opened as a template
(*.xlt), you could check the path.

sub auto_open()
if thisworkbook.path = "" then
'it hasn't been saved yet, you're working in a new workbook
else
'it's been saved at least once.
end if
end sub

or in the workbook_open event

Private Sub Workbook_Open()
if me.path = "" then
'it hasn't been saved yet, you're working in a new workbook
else
'it's been saved at least once.
end if
end sub

The Me keyword refers to the object that owns the code--in this case, it's the
ThisWorkbook module.
 
Back
Top