Auto Close

remmarg
03-22-2003, 06:43 PM
Can I make a Excel ask to close after 5 minutes. If I answer no to the message box it will automatically close if I answer yes it will start counting down another five minutes. Here is my feeble attempt. I can make it do everything but close the program instead it currently displays the message box saying "Bye Bye!!" I converted this from samples in the help file.

Module1

Sub shutdown()
'
' shutdown Macro
' Macro recorded 3/21/2003 by Jeff Grammer
'
'MsgBox "Is It OK To Close" 'Prompt,vbYesNo
Dim Msg1, Style, Title, Help, Ctxt, Response, MyString
Msg1 = "Do you want to continue ?" ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "Question" ' Define title.
Help = "DEMO.HLP" ' Define Help file.
Ctxt = 1000 ' Define topic
' context.
' Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.
MyString = "Yes" ' Perform some action.
GoTo 1
1 Application.OnTime Now + TimeValue("00:00:02"), "shutdown"
Else ' User chose No.
MyString = "No" ' Perform some action.
GoTo 2
2
MsgBox "Bye Bye!"

End If

End Sub

italkid
03-23-2003, 02:44 PM
Took a look at some code and came out whit this way :

In the Workbook_open window :

Sub Workbook_Open()
Dim DownTime As Date

DownTime = Now + TimeValue("00:00:10")
Application.OnTime DownTime, "ShutDown"

End Sub


Insert a module and put this code in

Sub ShutDown()
Dim Answer As String

Answer = MsgBox("Do you want to continue ?", vbInformation + vbYesNo)
If Answer = vbYes Then
GoOn
Else
ActiveWorkbook.Saved = True
ActiveWorkbook.Close
End If
End Sub
Sub GoOn()
Dim DownTime As Date

DownTime = Now + TimeValue("00:00:10")
Application.OnTime DownTime, "ShutDown"
End Sub


i set the time interval on 10 seconds for testing but you can change it in any possible way

Hope this helps and suit your needs.

remmarg
03-24-2003, 04:42 AM
Thanx I'll try this out today.




Took a look at some code and came out whit this way :

In the Workbook_open window :

Sub Workbook_Open()
Dim DownTime As Date

DownTime = Now + TimeValue("00:00:10")
Application.OnTime DownTime, "ShutDown"

End Sub


Insert a module and put this code in

Sub ShutDown()
Dim Answer As String

Answer = MsgBox("Do you want to continue ?", vbInformation + vbYesNo)
If Answer = vbYes Then
GoOn
Else
ActiveWorkbook.Saved = True
ActiveWorkbook.Close
End If
End Sub
Sub GoOn()
Dim DownTime As Date

DownTime = Now + TimeValue("00:00:10")
Application.OnTime DownTime, "ShutDown"
End Sub


i set the time interval on 10 seconds for testing but you can change it in any possible way

Hope this helps and suit your needs.

remmarg
03-24-2003, 03:01 PM
It works great!
I actually made two one to close the file that is currently open and used your suggestion "ActiveWorkbook.Close" and a second that actually closes Excel by replacing "ActiveWorkbook.Close" with "Application.Quit"


Thanks Again

italkid
03-25-2003, 03:12 AM
VB:
Sub Workbook_Open()
Dim DownTime As Date

DownTime = Now + TimeValue("00:00:10" )
Application.OnTime DownTime, "ShutDown"

End Sub


You only have to put "GoOn" in the Workbook_Open sub.
Little mistake from me.

Sub Workbook_Open()

GoOn

End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum