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
 

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

CaterinaAnna

Board Regular
Joined
Jun 15, 2009
Messages
85
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.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,135
Office Version
365
Platform
Windows
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.
 

CaterinaAnna

Board Regular
Joined
Jun 15, 2009
Messages
85
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 :)
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,329
Messages
5,510,635
Members
408,806
Latest member
Hunlight

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top