testing for the name of the file

P

Paul James

I would like to run a procedure when the workbook first opens that checks to
see what the name of the workbook is. The reason for this is that I've got
a specific name for the workbook encoded in other procedures, and if the
filename was changed before the workbook was opened, I'd like to notify the
user.

What code can I use to detect and return the name of the current workbook?

Thanks in advance,

Paul
 
C

Chip Pearson

Paul,

ActiveWorkbook.Name will return the name of the active workbook.
ThisWorkbook.Name will return the name of the workbook containing
that code.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
A

Anders S

Paul,

In the code for ThisWorkbook:

'*****
Private Sub Workbook_Open()
MsgBox Me.Name
End Sub
'*****

HTH
Anders Silven
 
B

Bob Phillips

Put the code in the Workbook_Open event in the Thisworkbook code module.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Top