Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Apr 2002
    Location
    Amersfoort, Utrecht, Netherlands
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    index of the current workbook (97)

    Post deleted by pjas

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: index of the current workbook (97)

    One way would be to use a public variable:

    Public wbkCurrent As Workbook

    At some point, set this variable to the active workbook:

    Set wbkCurrent = ActiveWorkbook

    From then on, you can refer to wbkCurrent without worrying about its name or index.

    Alternatively, if you know the name of the workbook, you can refer to it by name:

    Workbooks("MyWorkbook.xls")

  3. #3
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: index of the current workbook (97)

    You can refer to the workbook by name - e.g. <code>Workbooks("WorkBookName.xls")</code>

    Additionally, you can use a workbook variable to which you assign the current workbook, using either something like:
    <pre>Dim wbkCurrent as Workbook
    Set wbkCurrent = ActiveWorkbook
    </pre>

    or, if you open the workbook through code, you can assign it when you open it:
    <pre>Dim wbkCurrent as Workbook
    Set wbkCurrent = Workbooks.Open("pathnamehere")
    </pre>


    That way, you can just refer back to <code>wbkCurrent</code>
    and know that you are always referring to the correst workbook.
    HTH
    Regards,
    Rory

    Microsoft MVP - Excel

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: index of the current workbook (97)

    Nice to see we use the same naming convention! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: index of the current workbook (97)

    <img src=/S/yep.gif border=0 alt=yep width=15 height=15>

Posting Permissions

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