VBA to prevent workbook from opening at a set time of day

Dave8899

New Member
Joined
Jan 17, 2019
Messages
32
Hi all I’m looking for a way to prevent people from opening a workbook between 2-2:30pm every day. So it can be updated on the server.

I have set a Application.OnTime vba to close at a set time 1:59 and then repeated it every min until 2:29.

But people are still able to open the work book between 2/2:30 they kicked out after 1min but that has already stopped the update.

Dose anyone know of a way to prevent the workbook from opening between 2/2:30.

Thanks in advance
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi Dave,

In addition to your code to kick people out of the sheet, you can add a Workbook_Open() event.

ALT+F11 > Double Click 'This Workbook' > and paste in the following code:
Code:
Private Sub Workbook_Open()
    If Time >= TimeValue("14:00:00") And Time <= TimeValue("14:30:00") Then
        ThisWorkbook.Close SaveChanges:=False
    End If
End Sub

Cheers
Caleeco
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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