Retrieve Index of Activeworkbook?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This seems easy, but I'm not seeing it.

How do you retrieve the index of the workbooks collection which applies the
activeworkbook?

I guess one way would be to run through the Workbooks collection looking to
see if workbooks(i).name = activeworkbook.name

Is there a better way?

Thanks.
 
Don't know is this is what you want, but try it...

Dim x As Long, wbn As String, wb As Workbook

For Each wb In Application.Workbooks
x = Application.Windows(wb.Name).Index
wbn = wb.Name
Next

you could change wb.Name to Activeworkbook.Name
 
Hello Mark,

A Collection Object has both an Index and a Key Value associated with a
stored value. Unfortunataley, the object class doesn't support returning
the index by using the key value or vice versa. The only option you have
is to use a loop to go through the index numbers and compare the name
property to the ActiveWorkbook Name.

Sincerly,
Leith Ross
 
The only option you have is to use a loop to go through the index numbers
and compare the name property to the ActiveWorkbook Name.

Okay, thanks, Leith.

As you saw, that was the option that I thought of as I was posting the
question... guess that's the answer.

Rahmat ('thank you', in Kyrgyz).
 

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

Back
Top