Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Alert if the travel activity is after the work activity | Excel Worksheet Functions | |||
invalid names were detected in this workbook | Charts and Charting in Excel | |||
names were detected in this workbook | Charts and Charting in Excel | |||
Adding a chart to large workbook brings workbook activity to a hal | Excel Discussion (Misc queries) | |||
Stopping a Timer / Running a timer simultaneously on Excel | Excel Discussion (Misc queries) |