+ Reply to Thread
Results 1 to 8 of 8

Detect attempt to switch between open excel files (windows) during loop

  1. #1
    Registered User
    Join Date
    10-04-2013
    Location
    ID
    MS-Off Ver
    Excel 2003
    Posts
    4

    Detect attempt to switch between open excel files (windows) during loop

    Great forum for finding answers. Thanks for all the help in the past.

    Is it possible to detect when the user attempts to switch between open excel windows during the looping of this code? If the user minimizes the activewindow and selects another window the execution stops as desired. If the user attempts to switch between instances on the taskbar the code does not stop.

    Please Login or Register  to view this content.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Detect attempt to switch between open excel files (windows) during loop

    How about using:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    10-04-2013
    Location
    ID
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Detect attempt to switch between open excel files (windows) during loop

    xladept,

    The Workbook_deactivate event is raised by minimizing the workbook but the Workbook_worksheetDeactivate and Worksheet_Deactivate events never fire. None of the three occur when clicking on the open filename in the taskbar.

    Thanks

  4. #4
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Detect attempt to switch between open excel files (windows) during loop

    Are there multiple instances of Excel running?
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  5. #5
    Registered User
    Join Date
    10-04-2013
    Location
    ID
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Detect attempt to switch between open excel files (windows) during loop

    No. While the sub is looping other workbooks in the single instance of Excel cannot be activated without minimizing the activeworkbook (an action that I can't expect the user will perform reliably).

  6. #6
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Detect attempt to switch between open excel files (windows) during loop

    So you wish to stop the macro if a different application is activated?

  7. #7
    Registered User
    Join Date
    10-04-2013
    Location
    ID
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Detect attempt to switch between open excel files (windows) during loop

    Yes. I want the user to be able to suspend the zoom resizing of the frozen panes and select other open workbooks if needed.

  8. #8
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Detect attempt to switch between open excel files (windows) during loop

    I am confused again. You said there were no other instances of Excel running but you want the user to be able to select other workbooks. Selecting another workbook in the same instance of the Excel application will trigger the Workbook_Deactivate event no matter how you switch workbooks. The event will only fail to be raised when you switch to a different Excel instance. If you must detect that I think you will need the GetActiveWindow API function and test the result against Application.Hwnd - if they are different then you may stop your loop.

  9. #9
    Registered User
    Join Date
    10-04-2013
    Location
    ID
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Detect attempt to switch between open excel files (windows) during loop

    When two workbooks are open (book1 and zoombook for example) as windows within Excel I understand this to be one instance of Excel. If the macro is run in zoombook it prevents switching to book1 unless zoombook is minimized. I had looked at comparing the application.hwnd but don't have enough knowledge about the API function to make it work. The hwnd that I was trapping was of the zoombook window. I will look into that.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Open excel files in new windows
    By BDJones in forum Excel General
    Replies: 3
    Last Post: 07-02-2008, 12:20 PM
  2. Excel files won't open from Windows Explorer
    By AnotherEd in forum Excel General
    Replies: 3
    Last Post: 07-20-2006, 05:05 PM
  3. Replies: 1
    Last Post: 01-12-2006, 04:35 PM
  4. [SOLVED] How to open different files in different excel windows
    By Roger in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 01-05-2006, 11:39 PM
  5. [SOLVED] open excel files in different windows
    By Luciano Cunha in forum Excel General
    Replies: 5
    Last Post: 05-27-2005, 06:05 PM

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