LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Timer to close workbook when no activity detected

I had them in the wrong modules. Also, the person who submitted the code did
so a few times after changing a couple of the variables and had overlooked
changing them in every occurance. I finally got it working.

Thank you

Arlene

"Bob Phillips" wrote:

I haven't tested it, but it seems about right. Did you store the code in the
correct modules as suggested? If so, what happens when you run?

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"swedbera" wrote in message
...
I apologize,

I thought that my message was being posted along with the original message
from this other person. Here is the code.


Arlene

'xxxxx Paste to ThisWorkbook module xxxxx
Private Sub Workbook_Open()
Dim msg As String
msg = "This workbook will auto-close after " & WaitTime & _
" minutes of inactivity. "
MsgBox msg, vbInformation, "Auto-Close"
Call MakeToolBar
Call SetTime
End Sub

'xxxxx Paste to a standard module xxxxx
Option Explicit
Public Const WaitTime As Single = 0.1
Dim KillTime As Date
Dim TestTime As Date
Dim KillWithBtn As Boolean
Private Type POINTAPI
X As Long
Y As Long
End Type
Dim CursPos As POINTAPI
Private Declare Function GetCursorPos _
Lib "user32" (lpPoint As POINTAPI) As Long

Sub SetTime()
TestTime = Now + WaitTime / 1440
Application.OnTime TestTime, "TestForShutDown"
GetCursorPos CursPos
End Sub

Sub TestForShutDown()
Dim CP As POINTAPI
GetCursorPos CP
If CursPos.X = CP.X And CursPos.Y = CP.Y Then
With Application
.CommandBars("AutoClose").Visible = True
KillTime = Now + 0.1 / 1440
.OnTime KillTime, "Kill"
End With
Else
Call SetTime
End If
End Sub

Sub ContinueWorking()
With Application
.CommandBars("AutoClose").Visible = False
.OnTime KillTime, "Kill", Schedule:=False
End With
Call SetTime
End Sub

Sub Kill()
With Application
If Not .CommandBars.ActionControl Is Nothing Then
.OnTime KillTime, "Kill", Schedule:=False
End If
.CommandBars("AutoClose").Delete
End With
ThisWorkbook.Close True
End Sub
Sub Disable()
With Application
.CommandBars("AutoClose").Visible = False
If Now < KillTime Then .OnTime KillTime, "Kill", Schedule:=False
If Now < TestTime Then .OnTime TestTime, "TestForShutDown",
Schedule:=False
End With
End Sub

Sub MakeToolBar()
Dim CB As CommandBar
Dim Btn As CommandBarButton
Dim i As Integer
Dim arr As Variant, arr2 As Variant

With Application
.ScreenUpdating = False
On Error Resume Next
.CommandBars("AutoClose").Delete
On Error GoTo 0
Set CB = .CommandBars.Add("AutoClose", Temporary:=True)
End With
CB.Protection = msoBarNoResize
CB.Top = 200
CB.Left = 200
arr = Array("Continue Working", "Close Now", "Disable")
arr2 = Array("ContinueWorking", "Kill", "Disable")
For i = 0 To 2
Set Btn = CB.Controls.Add
With Btn
.Caption = arr(i)
.OnAction = arr2(i)
.Style = msoButtonCaption
.BeginGroup = (i 0)
End With
Next
Application.ScreenUpdating = True
CB.Visible = False
End Sub


"Bob Phillips" wrote:

Uh ... show the code?

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"swedbera" wrote in message
...
Regarding the inactivity timer that Greg Wilson was helping another

user
with....

I am unable to get this code to work. Does it need a reference or is
there
something missing here?

Please help.

Arlene








 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Alert if the travel activity is after the work activity Go Bucks!!! Excel Worksheet Functions 3 September 11th 09 05:44 PM
invalid names were detected in this workbook Joel Charts and Charting in Excel 2 July 5th 09 07:08 PM
names were detected in this workbook Joel Charts and Charting in Excel 2 July 5th 09 07:05 PM
Adding a chart to large workbook brings workbook activity to a hal Dale Excel Discussion (Misc queries) 6 December 29th 08 05:50 PM
Stopping a Timer / Running a timer simultaneously on Excel Paul23 Excel Discussion (Misc queries) 1 March 10th 06 12:08 PM


All times are GMT +1. The time now is 03:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"