excel - cannot select another workbook when macro enabled workbook open -


I have a macro enabled workbook that uses code to set the timer - this is a shared book and often Book people and leave your desk etc. It is set to save & amp; Turn off after 30 minutes of inactivity This function works fine, but the problem I am running is that when I have other workbooks, I can click on the tile (Windows 7) or alt + tab, surround them The only way to move ctrl + shift If this is just using the workbook that will not be an issue - does anyone know why this is happening? Post Code Below:

  Private Sub Workbook_Open () StartTimer End Sub Personal Sub Workbook_SheetChange (ByVal as a commodity, ByVal range as target) StartTimer End Sub Const idleTime = 1800 seconds Slow start sub StartTimer () Start = Timer while timer & lt; + IdleTime DoEvents Loop Application.DisplayAlerts = False ActiveWorkbook.Close true application.DisplayAlerts = True End Sub Start  

To start with

, I'm not completely sure why you are receiving that behavior, but please keep in mind. I have something to do with suspicious your busy-waiting loop (one with the DoEvents ), but it's just a hump Someone else may have a better (better) explanation. Anyway, maybe it's a good way to use you can schedule an operation to be at a certain time or interval and there is an option to cancel and change the scheduled action first. You will need that feature in the Workbook_SheetChange event handler

In short, you can do the following:.

  1. Save Add to a New Routine and Exit Workbook, let's call it: SaveWorkbookAndExit . It will be called by OnTime later
  2. Change the contents of your Workbook_SheetChange event handler like this:.

      Application.OnTime now + TimeValue ("00:30:00"), _ "SaveWorkbookAndExit", _ Schedule: = false  

    this basic form From the program routine SaveWorkbookAndExit should now be called in 30 minutes. Schedule: = Incorrect - Indicates that a predetermined process should be cleaned / aborted, which is very important.

  3. Add the same code to your workbook_on above the event handler However on the contrary, note that you schedule: = true Set up here!

And this is it. When the workbook is opened, a new SaveWorkbookAndExit operation is scheduled. Then, every time you go to Workbook_SheetChange , the scheduled operation will be canceled and a new schedule will be replaced instead.

I have not tested any of these, but I hope you get this idea. Please tell me if you want me to explain something else.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -