File name

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

Dave Peterson

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.
 

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