#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
PH NEWS
 
Posts: n/a
Default VBA

Hi All,

Is there a way I can enter a code in VBA that would protect my sheet if it
had been unprotected for say 5 minutes. Just to make that a bit clearer I
have a worksheet which is protected, I need the user to be able to unprotect
the worksheet by using a button. (that's the easy bit). But then I would
like the sheet to protect itself after 5 minutes

Thanks in advance

SPL


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bob Phillips
 
Posts: n/a
Default VBA

In the unprotect macro, you could add code to call an Ontime macro that will
protect it. If you also protect it using a button, you could add code in
that macro to cancel the call. Something like

Public nTime As Double

Sub ProtectButtonCode()
'your code
Application.OnTime nTime, "ProtectSheet", , False
End Sub

Sub UnprotectButtonCode()
nTime = Now + TimeSerial(0, 5, 0) '5 minutes
Application.OnTime nTime, "ProtectSheet"
End Sub

Sub ProtectSheet()
ActiveSheet.Protect
End Sub


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"PH NEWS" wrote in message
...
Hi All,

Is there a way I can enter a code in VBA that would protect my sheet if it
had been unprotected for say 5 minutes. Just to make that a bit clearer I
have a worksheet which is protected, I need the user to be able to

unprotect
the worksheet by using a button. (that's the easy bit). But then I would
like the sheet to protect itself after 5 minutes

Thanks in advance

SPL




  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
PH NEWS
 
Posts: n/a
Default VBA

Thanks Bob, but that's a bit over my head. I can't decipher between what I
need and what I don't need. I don't protect the sheet with a button it is
already protected. Could you tell me which part(s) of those codes I need if
all I want the button to do is unprotect the sheet for five minutes. This
would be a massive help.

Thanks in advance

SPL

"Bob Phillips" wrote in message
...
In the unprotect macro, you could add code to call an Ontime macro that

will
protect it. If you also protect it using a button, you could add code in
that macro to cancel the call. Something like

Public nTime As Double

Sub ProtectButtonCode()
'your code
Application.OnTime nTime, "ProtectSheet", , False
End Sub

Sub UnprotectButtonCode()
nTime = Now + TimeSerial(0, 5, 0) '5 minutes
Application.OnTime nTime, "ProtectSheet"
End Sub

Sub ProtectSheet()
ActiveSheet.Protect
End Sub


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"PH NEWS" wrote in message
...
Hi All,

Is there a way I can enter a code in VBA that would protect my sheet if

it
had been unprotected for say 5 minutes. Just to make that a bit clearer

I
have a worksheet which is protected, I need the user to be able to

unprotect
the worksheet by using a button. (that's the easy bit). But then I would
like the sheet to protect itself after 5 minutes

Thanks in advance

SPL






  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bob Phillips
 
Posts: n/a
Default VBA


"PH NEWS" wrote in message
...
Thanks Bob, but that's a bit over my head. I can't decipher between what I
need and what I don't need. I don't protect the sheet with a button it is
already protected.


I understand that, but when it gets unprotected (via your button) you want
it protected again, so I was suggesting adding another button for that where
you can add your specific code (as I showed).

Could you tell me which part(s) of those codes I need if
all I want the button to do is unprotect the sheet for five minutes. This
would be a massive help.


You could add this to your unprotect button code.


Dim Time As Double

nTime = Now + TimeSerial(0, 5, 0) '5 minutes
Application.OnTime nTime, "ProtectSheet"

and then just put this next macro into a standard code module.

Sub ProtectSheet()
ActiveSheet.Protect
End Sub


  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
PH NEWS
 
Posts: n/a
Default VBA

Fantastic. Thanks for the explanation Bob, a massive help.


"Bob Phillips" wrote in message
...

"PH NEWS" wrote in message
...
Thanks Bob, but that's a bit over my head. I can't decipher between what

I
need and what I don't need. I don't protect the sheet with a button it

is
already protected.


I understand that, but when it gets unprotected (via your button) you want
it protected again, so I was suggesting adding another button for that

where
you can add your specific code (as I showed).

Could you tell me which part(s) of those codes I need if
all I want the button to do is unprotect the sheet for five minutes.

This
would be a massive help.


You could add this to your unprotect button code.


Dim Time As Double

nTime = Now + TimeSerial(0, 5, 0) '5 minutes
Application.OnTime nTime, "ProtectSheet"

and then just put this next macro into a standard code module.

Sub ProtectSheet()
ActiveSheet.Protect
End Sub




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"