Help with Macro

BGY23

Well-known Member
Joined
Aug 13, 2008
Messages
515
Hi,
I was sure I posted this yesterday but can't find it in the forum.

Anyway I need to auto close a workbook afetr 15 minutes. Its read only to the users.

I found some code on the web to close the book after 15 minutes. What I need your help with is ..

1 When the workbook is opened a pop up message to tell the user it will close in 15mins
2 at 14mins tell them it will close in 1 min.

Here is the code I'm using to close the workbook.
Code:
Const idleTime = 15  'seconds
 Dim Start
 Sub StartTimer()
 Start = Timer
 Do While Timer < Start + idleTime
 DoEvents
 Loop
 Application.DisplayAlerts = False
 ActiveWorkbook.Close True
 Application.DisplayAlerts = True
 End Sub
Thanks
Brian
 
Last edited by a moderator:

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi,

For your first query. Try this code. Paste it in 'ThisWorkBook'.
Code:
Private Sub Workbook_Open()MsgBox "THIS WORKBOOK WILL BE CLOSED IN 15MIN", 64, "WARNING MSG:"
End Sub

This will Pop up a message "THIS WORKBOOK WILL BE CLOSED IN 15MIN". every time you will open this workbook.

Good Day!
PritishS
 
Upvote 0
Hi,

For ur second query.Try this code. This may be helpful

Code:
Sub Timer_at14()    MsgBox "YOU HAVE ONLY 1 MIN LEFT!!"
    Call test ' To Start timer again
End Sub


Sub test()
    Application.OnTime Now + TimeValue("00:14:00"), "Timer_at14"
End Sub

Thanks,

PritishS
 
Upvote 0
hello PritishS,

Thanks so much. The first one works just great. For the second one do I put that in "this workbook" or a new module or somewhere in the code I already have?


Brian
 
Upvote 0
hello PritishS,

Thanks so much. The first one works just great. For the second one do I put that in "this workbook" or a new module or somewhere in the code I already have?


Brian

Hi,
Put the code in a Module.

Thanks,
PritishS
 
Upvote 0
Thanks for all your help. I'll try it tomorrow. Its going home time in the UK :)
 
Upvote 0
Thanks for all your help. I'll try it tomorrow. Its going home time in the UK :)

You most welcome. Put that code in a 'New Module'. Have a nice day!!

Thanks
PritishS
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,792
Members
449,048
Latest member
greyangel23

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