Grab workbook name

CaterinaAnna

Board Regular
Joined
Jun 15, 2009
Messages
85
Sorry, another simple question from a novice ...

I want to use the name of an active workbook as a string later in a piece of code, but can't get the right syntax to find it and set it as a variable.

Name = ThisWorkbook.Name doesn't work because the code is in a different, master workbook and I don't really want to copy it to each individual book I want to process.

Thanks in advance for any help
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
That's what I thought, but it didn't work the first time I tried it: just returned the name of the book storing the macro. It's OK now though ...

Thank you.
 
Upvote 0
That's what I thought, but it didn't work the first time I tried it: just returned the name of the book storing the macro. It's OK now though ...
It returns the name of whatever the ACTIVE workbook is. So if it returned the name of the workbook storing the macro, then that is because when it was run, the macro workbook was the active workbook at the time.

I find the best time to "capture" the name of the other workbook is when you first open it. Then you should be assured of having the correct workbook active and capture the correct name.
 
Upvote 0
It returns the name of whatever the ACTIVE workbook is. So if it returned the name of the workbook storing the macro, then that is because when it was run, the macro workbook was the active workbook at the time..

Oh I'm aware of that, which is why it confused me: the one I wanted did seem to be active, but then it decided that no, what I was doing was running the macro, therefore that one was active. Might have been a stray cell select left behind that I later cleared out or something. Never mind, sorted now!

I find the best time to "capture" the name of the other workbook is when you first open it. Then you should be assured of having the correct workbook active and capture the correct name.

That is indeed where the command resides :)
 
Upvote 0

Forum statistics

Threads
1,213,522
Messages
6,114,112
Members
448,549
Latest member
brianhfield

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