richardtims
New Member
- Joined
- Jun 25, 2018
- Messages
- 31
Hello,
I found code in this forum to close my workbook after a certain amount of time, but when I use it, after closing the workbook, it wants to re-open it. Can anyone provide code that works or help me fix this one?
I found code in this forum to close my workbook after a certain amount of time, but when I use it, after closing the workbook, it wants to re-open it. Can anyone provide code that works or help me fix this one?
Code:
[COLOR=#333333]Public RunWhen As Double[/COLOR]
[COLOR=#333333]Public Const cRunIntervalSeconds = 300 ' this is 300 seconds or 5 Minutes[/COLOR]
[COLOR=#333333]Public Const cRunWhat = "The_Sub"[/COLOR]
[COLOR=#333333]Sub Auto_Open()[/COLOR]
[COLOR=#333333]RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)[/COLOR]
[COLOR=#333333]Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, _[/COLOR]
[COLOR=#333333]schedule:=True[/COLOR]
[COLOR=#333333]End Sub[/COLOR]
[COLOR=#333333]Sub The_Sub()[/COLOR]
[COLOR=#333333]'[/COLOR]
[COLOR=#333333]ActiveWorkbook.Save[/COLOR]
[COLOR=#333333]ThisWorkbook.Close savechanges:=True[/COLOR]
[COLOR=#333333]'[/COLOR]
[COLOR=#333333]Auto_Open[/COLOR]
[COLOR=#333333]End Sub[/COLOR]