close and save workbook on timer

jtodd

Board Regular
Joined
Aug 4, 2014
Messages
194
Hi
Sure this is a simple one .
I have a workbook that is used by multiple users ,
It updates every 10 mins with data from another source .
User have a habit of opening it and leaving it open ,
How can I close and save the workbook after a specified time , say half an hour
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Put this in the ThisWorkbook code module.

Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] Workbook_BeforeClose(Cancel [color=darkblue]As[/color] [color=darkblue]Boolean[/color])
    [color=darkblue]Call[/color] Closer_Cancel
[color=darkblue]End[/color] [color=darkblue]Sub[/color]


[color=darkblue]Private[/color] [color=darkblue]Sub[/color] Workbook_Open()
    [color=darkblue]Call[/color] Closer_Start
[color=darkblue]End[/color] [color=darkblue]Sub[/color]


Put this in any standard code module e.g.; Module1

Code:
[color=darkblue]Option[/color] [color=darkblue]Private[/color] [color=darkblue]Module[/color]


[color=darkblue]Dim[/color] CloseTime [color=darkblue]As[/color] [color=darkblue]Date[/color]


[color=darkblue]Public[/color] [color=darkblue]Sub[/color] Closer_Start()
    CloseTime = Now + TimeValue("00:30:00")
    Application.OnTime CloseTime, "Closer"
[color=darkblue]End[/color] [color=darkblue]Sub[/color]


[color=darkblue]Public[/color] [color=darkblue]Sub[/color] Closer_Cancel()
    [color=darkblue]On[/color] [color=darkblue]Error[/color] [color=darkblue]Resume[/color] [color=darkblue]Next[/color]
    Application.OnTime CloseTime, "Closer", Schedule:=[color=darkblue]False[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]


[color=darkblue]Private[/color] [color=darkblue]Sub[/color] Closer()
    ThisWorkbook.Close SaveChanges:=[color=darkblue]True[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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