ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   File name (https://www.excelbanter.com/excel-programming/431035-file-name.html)

Rpettis31

File name
 
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.

Bob Phillips[_3_]

File name
 
If Activeworkbook.Name < mytemplate Then Exit Sub

--
__________________________________
HTH

Bob

"Rpettis31" wrote in message
...
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.




Dave Peterson

File name
 
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.


Rpettis31 wrote:

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.


--

Dave Peterson


All times are GMT +1. The time now is 07:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com