testing for the name of the file

  • Thread starter Thread starter Paul James
  • Start date Start date
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
 
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
 
Paul,

In the code for ThisWorkbook:

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

HTH
Anders Silven
 
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)
 
My thanks to Chip, Bob and Anders. You've given me exactly what I needed.
 

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

Back
Top