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
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