Auto Closing of excel

ian0530

New Member
Joined
Mar 2, 2012
Messages
20
Hi Everyone please help with my problem.
I have these codes that automatically run at specified time stated in the macro,
But I would like to run it with time preferred by the user without editing the
time inside the program
Eg: I would like to run it for 10 minutes only. Upon opening the workbook
the inputbox will appear for user to set time. Thanks in advance!!!






Sub Workbook_BeforeClose(Cancel As Boolean)
'
Application.OnTime dTime, "ian", , False
End Sub
Sub Workbook_Open()


Application.OnTime Now + TimeValue("01:00:30"), "close"
End Sub






Public dTime As Date
Sub close()
dTime = Now + TimeValue("01:00:30")
Application.OnTime dTime, "close"


Windows("CLOSE.xls").Activate
ActiveWindow.Close False
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Public Sub Workbook_Open()

[put the procedures you want to run when the workbook is opened and before the workbook is saved and closed here]

SaveAndClose
End Sub


Public Sub SaveAndClose()
ActiveWorkbook.Save
Application.Quit
End Sub

Take care though ie you need to create a copy of the workbook without this code because
once you put that code in it will become difficult to edit the worksheet (another way would be to hold down the SHIFT key
when the workbook is opening to stop procedure from running)

Also it is better to use the Windows Task Scheduler rather than the Application.OnTime for somewhat "infrequent" tasks
 
Upvote 0

Forum statistics

Threads
1,214,375
Messages
6,119,164
Members
448,870
Latest member
max_pedreira

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top