+ Reply to Thread
Results 1 to 5 of 5

Referencing a Workbook by Index

  1. #1
    Registered User
    Join Date
    01-28-2007
    Location
    Reading, Berkshire, UK
    Posts
    26

    Referencing a Workbook by Index

    Hi everyone,

    Is there a way of getting the index of an open workbook (its position in the collection) from its name?

    So for instance I can do this (in the immediate window):
    ?Workbooks(2).Name

    and I'll get back the name of the second workbook, "Feb_Sales.xlsx".

    But I can't do something like this:

    ?Workbooks("Feb_Sales.xlsx").index

    But, you can use 'index' like this on Worksheets within a Workbook. Is there an equivalent for doing the same thing for Workbooks?

    Any pointers, gratefully received as always.

  2. #2
    Registered User
    Join Date
    07-27-2010
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Referencing a Workbook by Index

    Hi Jamsta1972,

    A quick look in the object browser shows that there doesn't seem to be an equivalent property for the workbook class, but there's nothing to stop you creating your own array of workbooks.

    Cheers,
    Dom

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Referencing a Workbook by Index

    Hi jamsta1972,

    I'd write a short loop using something like:

    Please Login or Register  to view this content.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    01-28-2007
    Location
    Reading, Berkshire, UK
    Posts
    26

    Re: Referencing a Workbook by Index

    OK, thanks guys. A loop it shall be!

  5. #5
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: Referencing a Workbook by Index

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save
    Would you like to say thanks? Please click the: " Add Reputation" button, on the grey bar below the post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1