.VBA objects help - current workbook name?

Gates Is Antichrist

Well-known Member
Joined
Aug 15, 2002
Messages
1,961
Yeah, I know that ActiveWorkbook.Name is the current workbook. Instead, what I'd like is to know the name of the workbook that the currently running code exists in. You know, the one in the Windows Title bar of the VBE (code) window?

That may be different than ActiveWorkbook, either because either the active workbook has changed since starting the code, or the code was invoked from another workbook in the first place. Consider running a sub that's in PERSONAL.xls - that's invoked while FOO.XLS is active. If it's always hidden, heck yeah it would not be .ActiveWorkBook. So my objective is: is there then a variable whose content is "PERSONAL.XLS" ?

Is there an "Owner of the VBE" variable?
 

Some videos you may like

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Greg Truby

MrExcel MVP
Joined
Jun 19, 2002
Messages
10,014
GIA - as SVR has indicated, normally that's going to be ThisWorkbook which is the default name. But if you've gone in and renamed the VB Project using the Properties window, then it will be whatever that is. In the VBE Project Explorer window you'll see the actual project names if they've been renamed otherwise the VBE puts up the generic "VBAProject" for the name. The workbook's file name follows in parenthesis.

HTH
 

Gates Is Antichrist

Well-known Member
Joined
Aug 15, 2002
Messages
1,961
sweater: In thousands of years of schlepping through code I've never seen ThisWorkbook except in the Project Window - whoda thunk it had a place in code? Now I know. Way to go!

P.S. Your avatar is peripherally freaking me out. That's saying a log coming from me!!

Greg - excellent augmentation. Thank you too.
 

Greg Truby

MrExcel MVP
Joined
Jun 19, 2002
Messages
10,014
Actually, I fear that in my initial post, I mixed two separate items; treating them as if they were the same thing. The name of the project appears to the left of the workbook's file name as the parent object in the Project Explorer window and has the default value of "VBAProject". The workbook's codename shows underneath the project header and has the default name "ThisWorkbook". This is what you were after, GIA.

To edit either the project name or the workbook codename, you can use the Properties window. Sorry that my previous post was misleading.
 

Watch MrExcel Video

Forum statistics

Threads
1,118,079
Messages
5,570,083
Members
412,310
Latest member
mark884
Top