ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Timed closing code questions (https://www.excelbanter.com/excel-programming/399285-timed-closing-code-questions.html)

Mike K

Timed closing code questions
 
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

--
HTH...



Chip Pearson

Timed closing code questions
 
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)


"Mike K" wrote in message
...
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

--
HTH...




Mike K

Timed closing code questions
 
Awesome, Thanks Chip!

"Chip Pearson" wrote:

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)


"Mike K" wrote in message
...
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

--
HTH...





All times are GMT +1. The time now is 06:56 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com