+ Reply to Thread
Results 1 to 18 of 18

Open Workbook [Excel 1/201] (VBA Only)

  1. #1
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Open Workbook [Excel 1/201] (VBA Only)

    I can't seem to get the next bit of code working correctly. I used to have it check for certain books but the listing had gotten so long I need to shorten it.

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Open Workbook [Excel 1/201] (VBA Only)

    What's the code meant to do and how is it not working?
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Open Workbook [Excel 1/201] (VBA Only)

    It's supposed to test for other open workbooks and advise them to close them.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Open Workbook [Excel 1/201] (VBA Only)

    Are you only looking for workbooks with 'OpenBook' in the name?

  5. #5
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Open Workbook [Excel 1/201] (VBA Only)

    No I was going to try to use the name of the workbook that runs the code and an IF NOT x then y statement to make sure all other workbooks are giving the correct msgbox to close them.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Open Workbook [Excel 1/201] (VBA Only)

    If you want to check if there are other workbooks than the one the code is in are open use this.
    Please Login or Register  to view this content.
    PS What are you doing with iError?

  7. #7
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Open Workbook [Excel 1/201] (VBA Only)

    The code is called from another Sub(). It passes along a True/False value then indicates what that main Sub() does next.

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Open Workbook [Excel 1/201] (VBA Only)

    It isn't passing iError anywhere.

  9. #9
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Open Workbook [Excel 1/201] (VBA Only)

    You're right. Here is how it was called...

    Please Login or Register  to view this content.
    I'm not sure what I did wrong...

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Open Workbook [Excel 1/201] (VBA Only)

    Try declaring iError in the calling sub and changing openCheck to this.
    Please Login or Register  to view this content.
    Which you can call like this.
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Open Workbook [Excel 1/201] (VBA Only)

    That worked wonders. Thank you!

  12. #12
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Open Workbook [Excel 1/201] (VBA Only)

    Going back to the original issue... if I have two workbooks open and both contain the new code it causes a problem. Which is why I'm trying to get this code working. So that any workbook open (and they ALL use Ctrl-e to initiate the macro) will not cause a conflict.

    Not sure of a solution.

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Open Workbook [Excel 1/201] (VBA Only)

    Sorry I'm a little confused.

    What exactly are you trying to do?

    How does having the code in more than one workbook cause problems?

  14. #14
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Open Workbook [Excel 1/201] (VBA Only)

    Like I said, all the workbooks that run the main portion of the macro (this section is only a subfunction to see if any other ones are open) all use Ctrl-e and all do different things. So if I have two workbooks open, Excel may run a different macro then expected. Since not all do the same thing or have similar worksheets, it can err out.

    Also since there are muliple sub, functions, etc I can't simply train the braindead people I work with to run the correct one. They have a hard enough time using the simples ones...

  15. #15
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Open Workbook [Excel 1/201] (VBA Only)

    Don't use the same shorcut key for the subs.

    Why not use buttons to run them instead??

  16. #16
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Open Workbook [Excel 1/201] (VBA Only)

    There is only a limited number of key shortcuts available. The braindead people I work with are used to the one key shortcut.

    There isn't enough room on the screen to use buttons. The forms take up the whole of the screen and the buttons cannot be on the printed forms in the end result.

  17. #17
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Open Workbook [Excel 1/201] (VBA Only)

    How about one button that opens a userform which has buttons on it to run the code?

    The button on the worksheet can be set not to print.

  18. #18
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Open Workbook [Excel 1/201] (VBA Only)

    There are around 30-40 different spreadsheets, each with a minimum of 1 worksheet to a maximum of 6. The code being run is dependent on the open workbook AND the correct worksheet.

    I just don't know (what I'm doing). I'm limited by management from being able to go back and change something that's already serving its purpose.

+ 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