Hi I would like to know how could I make a Sub called lets say Teste() to be executed after 30 minutes of excel inactivity.
Any ideas?
Hi I would like to know how could I make a Sub called lets say Teste() to be executed after 30 minutes of excel inactivity.
Any ideas?
Best Regards,
Carlos Paleo.
To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.
If Debugging is harder than writing a program and your code is as good as you can possibly make
it, then by definition you're not smart enough to debug it.
http://www.mugrs.org
im sure theres a better way but you could use the following code in the Worksheet_SelectionChange event if your only using one sheet, its worked for me in the past but didnt really like this option
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim vartimer As Variant ' The next line sets the time in hours, minutes and seconds vartimer = Format(Now + TimeSerial(0, 30, 0), "hh:mm:ss") If vartimer = "" Then Exit Sub ' The action of the timer is to call a nother macro called test Application.OnTime TimeValue(vartimer), "test" End Sub
Hi Carlos,
If you haven't visited Chip Pearson's site yet, you may want to give it a go. He has a scheduling sub here
Personally, I'd set that up, then maybe reset the timer constantly using this event in the "ThisWorkbook" module:
In this fashion, every time the user makes a change to any sheet, the timer should be reset. If they sit idle, it won't be and voila!Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range) Call StartTimer End Sub
Having said that, I've never tried it myself!
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!
Hi guys,
thank you very much. I much appreciated this site Ken, thanks.
Best Regards,
Carlos Paleo.
To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.
If Debugging is harder than writing a program and your code is as good as you can possibly make
it, then by definition you're not smart enough to debug it.
http://www.mugrs.org
Problem solved!
Best Regards,
Carlos Paleo.
To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.
If Debugging is harder than writing a program and your code is as good as you can possibly make
it, then by definition you're not smart enough to debug it.
http://www.mugrs.org
No problem. Chip's got a ton of awesome info in there about a variety of things.Originally Posted by Paleo
So what was the answer?Originally Posted by Paleo
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!
Hi Ken sorry for not posting it here in the first place:
Here is it:
At This_Workbook
Private Sub Workbook_SheetActivate(ByVal Sh As Object) Call Timer End Sub Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) Call Timer End Sub
At Module1
Public vartimer As Variant Sub Timer() On Error Resume Next Application.OnTime earliesttime:=vartimer, _ procedure:="Fecha", schedule:=False On Error GoTo 0 vartimer = Format(Now + TimeSerial(0, 30, 0), "hh:mm:ss") If vartimer = "" Then Exit Sub Application.OnTime TimeValue(vartimer), "Fecha" End Sub
Best Regards,
Carlos Paleo.
To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.
If Debugging is harder than writing a program and your code is as good as you can possibly make
it, then by definition you're not smart enough to debug it.
http://www.mugrs.org
Hey Carlos,
Just a thought, but you might want to through in a Workbook_Deactivate or Worksheet_SheetDeactivate to turn the timer off as well. Maybe even a Workbook_BeforeClose.
I'm not sure about the latter, but if you drop your routines in, then move to another book, it will still trigger the macro.
Could be your intention though...
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!
Hi Ken,
yes, actually thats my intention. If its not active I am gonna close it using the Sub Fecha() that in portuguese means "close".
Best Regards,
Carlos Paleo.
To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.
If Debugging is harder than writing a program and your code is as good as you can possibly make
it, then by definition you're not smart enough to debug it.
http://www.mugrs.org
Fair enough, but I'd still recommend turning the timer off in the "Workbook_BeforeClose" event.
At least make sure you test it with another WB open and see what happens.
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!
Why should I put it at Workbook_BeforeClose? If its closed the timer will be killed anyway?
The second assumption is pretty right in my case because I have coded to close the application, not only the workbook, so if its leaved to work on another workbook, both are gonna be closed. But that was intentional. (Is it a ditactorial code or what? )
You know, sometimes I just feel I kinda hate the user and start punishing he/she
. (just kidding)
Best Regards,
Carlos Paleo.
To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.
If Debugging is harder than writing a program and your code is as good as you can possibly make
it, then by definition you're not smart enough to debug it.
http://www.mugrs.org
Try this...
Open two workbooks. Copy all your code into workbook1, setting the time to 1 mintue instead of 30. Then go clicking around the sheet1 in Workbook1. Now close Workbook1.
Just sit in Workbook2 for about a minute. Betcha you see an error.
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!
Gee, that was unexpected. But, well, you are right as usual. I will use that Workbook_BeforeClose then.
Thanks again
Best Regards,
Carlos Paleo.
To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.
If Debugging is harder than writing a program and your code is as good as you can possibly make
it, then by definition you're not smart enough to debug it.
http://www.mugrs.org
Hi Ken,
made the change and it works great now. Thanks again.
Best Regards,
Carlos Paleo.
To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.
If Debugging is harder than writing a program and your code is as good as you can possibly make
it, then by definition you're not smart enough to debug it.
http://www.mugrs.org
30 minutes inactivity? Seems like your tea breaks are way too long!!!
Yeap, it was 10 minutes but people asked me to make it longer. They must be dating some data in the workbook to stare so long looking at it...
Best Regards,
Carlos Paleo.
To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.
If Debugging is harder than writing a program and your code is as good as you can possibly make
it, then by definition you're not smart enough to debug it.
http://www.mugrs.org
Hi Carlos,
You're welcome!
I'm fairly certain (it's been a while since I read Chip's page) that the way this one actually works is to schedule the event to be called later. The problem is that it stays in Excel's memory until the thing is turned off, so even if the workbook is closed, it stills hangs out there.
For the benefit of anyone else reading this, that's why I recommended the Deactivate events as well. If you don't want it to fire when you activate a different workbook, you will want to turn it off from one of those events.
Originally Posted by mdmackillop
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!
Dang, here I go alter it again, but as you were right before I wont even argue.
Altering it.....
Best Regards,
Carlos Paleo.
To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.
If Debugging is harder than writing a program and your code is as good as you can possibly make
it, then by definition you're not smart enough to debug it.
http://www.mugrs.org
Well hang on!
If you want the workbook to close even if someone is in another one, it's fine as is. It's only if you don't want it to close that you'd need to modify it!
(Sorry, best smilie there was for the situation!)
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!
Oh no, then it was right. I want it to close even if someone is in another one.
Best Regards,
Carlos Paleo.
To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.
If Debugging is harder than writing a program and your code is as good as you can possibly make
it, then by definition you're not smart enough to debug it.
http://www.mugrs.org