Captured the system idle time

vasuki

New Member
Joined
Jan 8, 2019
Messages
1
Hi,

In Excel using macro for Captured the system idle time.I Was using separate sheet in Module & separate folder.

but i got the some error was " Cannot run the macro "D:\Vasuki\M\file.xlsm'!This workbook.time.Out'. the macro may not be available in this workbook or all macro may be disable".

Kindly please review & give solution


Code:::

Option Explicit


'edit these three constants
Private Const Hours As Integer = 0
Private Const Minutes As Integer = 0
Private Const Seconds As Integer = 10


Private when As Variant


Private Sub Workbook_Open()
MsgBox "The workbook, " & ThisWorkbook.Name & _
", will be closed (saved) if inactive for more then " & Hours & " hours, " _
& Minutes & " minutes, and " & Seconds & " seconds." _
, 10, "ACTIVITY"
time_out (True)
End Sub


Private Sub Workbook_SheetActivate(ByVal Sh As Object)
restart
End Sub


Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
restart
End Sub


Private Sub Workbook_Activate()
restart
End Sub


Private Sub Workbook_BeforeClose(Cancel As Boolean)
cancel_schedule
End Sub


Sub restart()
cancel_schedule
time_out (True)
End Sub


Sub time_out(Optional flag As Boolean)
'Erik Van Geit
Dim action As Integer
Dim file_name As String


If flag Then
when = Now + TimeSerial(Hours, Minutes, Seconds)
Application.OnTime when, "ThisWorkbook.time_out"
Exit Sub
End If


With ThisWorkbook
cancel_schedule
.Close True
End With


End Sub


Private Sub cancel_schedule()
On Error Resume Next
Application.OnTime EarliestTime:=when, Procedure:="ThisWorkbook.time_out", schedule:=False
On Error GoTo 0
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top