+ Reply to Thread
Results 1 to 6 of 6

Using Workbook Index as Condition to Auto Close

  1. #1
    Forum Contributor
    Join Date
    09-13-2012
    Location
    Midwest
    MS-Off Ver
    Excel 365
    Posts
    124

    Using Workbook Index as Condition to Auto Close

    I have 2 kinds of workbooks that must be opened in order. However, I cannot specify the workbooks in the code because they will always be different files (Master file opened first followed by subsidiary file) so I am using the workbook index since there will only be 2 files opened at a time and they must be opened in a certain order. I dont know why the following code isnt working; I've tried activeworkbook with no success as well.
    Please Login or Register  to view this content.
    Then I would apply similar code to the 2nd workbook except with Workbooks(2) and a different msgbox.
    Any help is MUCH appreciated.
    Thank you.

    Luke

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Using Workbook Index as Condition to Auto Close

    Hi, Luke,

    where did you place the code? If it´s your personal workbook you will have 3 workbooks open. I would suggest you work with objects on opening the workbooks instead of their index (maybe using GetOpenFilename for the path and name of Workbook).

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Contributor
    Join Date
    09-13-2012
    Location
    Midwest
    MS-Off Ver
    Excel 365
    Posts
    124

    Re: Using Workbook Index as Condition to Auto Close

    The code is placed in THISWORKBOOK. The reason I'm trying to stay away from file names is because there are around 15 different Master files that will be the first workbook open, then around 20 different subsidiary files that could be the second workbook open. So I'd like to stay away from naming all these different files in the coding. When it comes to coding, my thought process can be somewhat linear, so if I am not understanding what you suggested, can you please provide a brief example?
    Also, the computers running these two workbooks will be dedicated kiosks so there is no interference with any other workbooks.
    Danke für jede Hilfe (google translate).

    Luke

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Using Workbook Index as Condition to Auto Close

    Hi, Luke,

    maybe try this change which will count the number of workbooks in the instance:
    Please Login or Register  to view this content.
    Maybe you should alter the code to open the second workbook from this procedure.
    Please Login or Register  to view this content.
    Ciao,
    Holger

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Using Workbook Index as Condition to Auto Close

    Quote Originally Posted by lsteinbach View Post
    The code is placed in THISWORKBOOK. The reason I'm trying to stay away from file names is because there are around 15 different Master files that will be the first workbook open, then around 20 different subsidiary files that could be the second workbook open. So I'd like to stay away from naming all these different files in the coding. When it comes to coding, my thought process can be somewhat linear, so if I am not understanding what you suggested, can you please provide a brief example?
    Also, the computers running these two workbooks will be dedicated kiosks so there is no interference with any other workbooks.
    Danke für jede Hilfe (google translate).

    Luke
    If the "master" workbooks only have the macro then try something like this...

    Please Login or Register  to view this content.
    Alternatively, you could loop through each opened workbook and look for a difference (cell.value, sheet name) that distinguishes a Master from a Subsidiary.
    Last edited by AlphaFrog; 05-30-2013 at 01:01 AM.

  6. #6
    Forum Contributor
    Join Date
    09-13-2012
    Location
    Midwest
    MS-Off Ver
    Excel 365
    Posts
    124

    Re: Using Workbook Index as Condition to Auto Close

    Thanks for the ideas! The workbook.count is exactly what I was looking for. Ill be able to alter what you guys provided to suit me as needed. Thank you both!

    Luke

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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