Getting the workbook number via VBA code

E

EAB1977

Hello ladies and gentleman,

I am stuck with a problem and wondering if someome could help me to
figure it out.

What I want to do is to be able to grab the workbook number from a user
that may have multiple workbooks open at one time.

For example, lets say that a user has workbook1, workbook2 workbook3,
workbook4, and workbook5 open. If you go to the Window Menu, you will
see that it looks like:

1 - workbook1
2 - workbook2
etc...

What I need to grab is the workbook number and place it in my code so I
can call it:

strWorkbookName = Workbooks(Workbooks.Count).Name

I thought that this would bring up the latest workbook that was opened,
but this doesn't seem to be the case.

Any ideas?
 
L

Leith Ross

Hello EAB1977,

You were close. To get all the Workbooks the user has open and stor
them in an array...


Dim strWorkbookName()

ReDim strWorkbooName(Workbooks.Count)

For I = 1 To Workbooks.Count
strWorkbookName(I) = Workbooks(I).Name
Next I

Use ActiveWorkbook.Name to return the current Workbook that the use
is in.

Sincerely,
Leith Ros
 

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