Kemidan2014
Board Regular
- Joined
- Apr 4, 2022
- Messages
- 229
- Office Version
- 365
- Platform
- Windows
I am having issues running some new coding that I found from googling.
All in all the code DOES work fine but its when I ADDED in "Workbook_beforeclose"
UpdatemasterAACT
ThisWorkbook.Save
Where updatemasterAACT is another Macro i have that is tied to a button. When you run it on its own perfectly fine, never faults
When i CLICK but X button to close excel, Runs it just fine never faults
but when the TIMER runs out to close excel due to inactivity THEN i start getting run time errors when UpdatemasterrAACT macro runs.
I am not sure why trying to close Excel on a timer vs closing excel intentionally could cause code to error. I see zero reason to alter the code in UpdatemasterAACT if it can run fine with out errors normally So i BELIEVE my solution is changing something in the code I posted Below
Following code is in a standard module
The next set of Code is in "Thisworkbook"
All in all the code DOES work fine but its when I ADDED in "Workbook_beforeclose"
UpdatemasterAACT
ThisWorkbook.Save
Where updatemasterAACT is another Macro i have that is tied to a button. When you run it on its own perfectly fine, never faults
When i CLICK but X button to close excel, Runs it just fine never faults
but when the TIMER runs out to close excel due to inactivity THEN i start getting run time errors when UpdatemasterrAACT macro runs.
I am not sure why trying to close Excel on a timer vs closing excel intentionally could cause code to error. I see zero reason to alter the code in UpdatemasterAACT if it can run fine with out errors normally So i BELIEVE my solution is changing something in the code I posted Below
Following code is in a standard module
VBA Code:
Option Explicit
Dim killtime As Variant
Dim procedurename As String
Sub Starttimer()
Stoptimer
killtime = Now + TimeValue("00:10:00")
procedurename = "Closethisworkbook"
Application.OnTime killtime, procedurename
End Sub
Sub Startconfirm()
Stoptimer
killtime = Now + TimeValue("00:00:10")
procedurename = "CloseWorkbook"
Application.OnTime killtime, procedurename
End Sub
Sub Stoptimer()
On Error Resume Next
Application.OnTime killtime, procedurename, , False
End Sub
Sub Closethisworkbook()
Stoptimer
ThisWorkbook.Close Savechanges:=True
End Sub
The next set of Code is in "Thisworkbook"
Code:
Private Sub Workbook_Activate()
Starttimer
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Stoptimer
UpdatemasterAACT
ThisWorkbook.Save
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Starttimer
End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Starttimer
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Starttimer
End Sub