Excel 2003 VBScript

G

Guest

Hi,

I need some help in finding the file name of the currently opened worksheet
in excel. Is there an easy function such as Environ() that can be used to
find the current opened file?

Thanks,
Ryan
 
G

Guest

Sub ordinate()
MsgBox (ActiveSheet.Name)
End Sub

for the sheet name

Sub ordinate()
MsgBox (ActiveWorkbook.Name)
End Sub

for the workbook name
 
C

Chip Pearson

You can reference either of two files directly: the object ActiveWorkbook is
a reference to the workbook that is active in the main Excel window. This
may not be the same workbook that contains the executing code. The
ThisWorkbook object refers to the workbook containing the executing code,
which may not be the same workbook that is active in the main Excel window.
From either of these you can use the Name or FullName properties to get the
Name (file name without drive or directory info) or the complete file name
(including drive and folder information). E.g.,

Debug.Print ActiveWorkbook.Name
Debug.Print ThisWorkbook.FullName


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)
 
G

Guest

Thank you very much! I should have searched the forums...I believe the
answer has been posted before.
 
G

Guest

Sub location()
MsgBox ActiveSheet.Name 'sheet name
MsgBox ActiveWorkbook.Name 'filename
MsgBox ActiveWorkbook.Path 'path

End Sub
 

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