+ Reply to Thread
Results 1 to 4 of 4

Run macro if no mouse movement and workbook active

  1. #1
    Registered User
    Join Date
    12-22-2011
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2010
    Posts
    58

    Run macro if no mouse movement and workbook active

    Hello,

    I have a workbook - Book1.xlsb.
    Is it possible to run a macro only if the workbook is active AND there is no mouse movement? Const idleTime doesn't include mouse movement.

    Thanks

  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: Run macro if no mouse movement and workbook active

    Hi, Subject_Name_Here,

    maybe you should indicate the action to be taken from the macro. From what I read you may want to close the workbook after a certain time of inactivity (the variable idleTime may be used for that). So the OnTime may be called from ThisWorkbook and either the Workbook_SheetChange or Workbook_SheetSelectionChange events as well.

    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
    Registered User
    Join Date
    12-22-2011
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2010
    Posts
    58

    Re: Run macro if no mouse movement and workbook active

    Yes, the action would be to call macro2. Very simple. I'm just not sure if or how VBA would detect no mouse movement.

  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: Run macro if no mouse movement and workbook active

    Hi, Subject_Name_Here,

    AFAIR the mouse movement directly could only be monitored by using API. If a user works in a workbook there should either be a Selection of a new cell by scrolling or directy choosing a cell (causing the Workbook_SheetSelectionChange event to trigger) or any entry or change to a cell (that would call the Workbook_SheetChange). Both events should be placed in ThisWorkbook (or DieseArbeitsmappe in the german version). Calling the macro from these events would also cover the workbook to be placed in the tray.

    If you need help on how to place the code you could have a look at this german site where you may download sample files which are commented.

    HTH,
    Holger

+ 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