Timed closing code questions

M

Mike K

Oh Wise Ones,

Heres a bit of code from Jim Thomlinson that saves and closes a workbook
after a set amount of time, but prompts the user for some more time. Works
great. I have 2 questions though.

1) If multiple people share a computer, will the Windows Script Host Object
Model flag be present for ALL people on that PC if it is set by the first
person?

2) I and not a programmer, but I would guess that the Windows Script Host
Object Model flag is set in the registry. Instead of running around to 30+
computers, can I package this in a reg file and email it out?


Sub Auto_Open()
Application.OnTime Now() + TimeValue("00:00:20"), "CloseMe"
End Sub

'requires reference to "Windows Script Host Object Model"
Public Sub CloseMe()
Dim SH As IWshRuntimeLibrary.WshShell
Dim Res As Long

Set SH = New IWshRuntimeLibrary.WshShell
Res = SH.Popup(Text:="Are you still there?", secondstowait:=2, _
Title:="Active", Type:=vbYesNo)
If Res = vbYes Then
Application.OnTime Now() + TimeValue("00:00:20"), "CloseMe"
Else
ThisWorkbook.Save
ThisWorkbook.Close
End If
End Sub
 
C

Chip Pearson

If by "flag" you mean the reference in the VBA Project to the WSH library,
that setting is saved within the workbook itself. If you use the workbook on
any other machine, WSH will be loaded automatically when the workbook opens.
You don't need to manually set the reference yourself.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)
 
M

Mike K

Awesome, Thanks Chip!

Chip Pearson said:
If by "flag" you mean the reference in the VBA Project to the WSH library,
that setting is saved within the workbook itself. If you use the workbook on
any other machine, WSH will be loaded automatically when the workbook opens.
You don't need to manually set the reference yourself.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top