.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?
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
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
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,215,039
Messages
6,122,799
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top