• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Macro to lock a workbook after a specific date

Indranil_Guha

New Member
Hello all Excel Ninjas,

I am trying to protect a work book so that no one can edit the file after a specific date and I would prefer to input that date in the macro instead of in a cell in the workbook. Could anyone please help me on this?
 
This simple example assumes that there is only a single sheet in the workbook and that macros are enabled. In a Standard Module enter:

Code:
Sub FreezeMe()
    Dim keyy As String, sh As Worksheet
    keyy = "obvious"
    Set sh = ActiveSheet
   
    sh.Unprotect Password:=keyy
        Cells.Locked = True
    sh.Protect Password:=keyy
End Sub

and in the Workbook code area enter:

Code:
Private Sub Workbook_Open()

    If Date >= DateSerial(2015, 12, 25) Then
        Call FreezeMe
    End If
End Sub
 
Is this.

Code:
PrivateSub Workbook_Open()
  If Date > DateSerial(2015, 12, 25) Then sheets("abc").protect 123
End Sub
 
This simple example assumes that there is only a single sheet in the workbook and that macros are enabled. In a Standard Module enter:

Code:
Sub FreezeMe()
    Dim keyy As String, sh As Worksheet
    keyy = "obvious"
    Set sh = ActiveSheet
  
    sh.Unprotect Password:=keyy
        Cells.Locked = True
    sh.Protect Password:=keyy
End Sub

and in the Workbook code area enter:

Code:
Private Sub Workbook_Open()

    If Date >= DateSerial(2015, 12, 25) Then
        Call FreezeMe
    End If
End Sub
This simple example assumes that there is only a single sheet in the workbook and that macros are enabled. In a Standard Module enter:

Code:
Sub FreezeMe()
    Dim keyy As String, sh As Worksheet
    keyy = "obvious"
    Set sh = ActiveSheet
  
    sh.Unprotect Password:=keyy
        Cells.Locked = True
    sh.Protect Password:=keyy
End Sub

and in the Workbook code area enter:

Code:
Private Sub Workbook_Open()

    If Date >= DateSerial(2015, 12, 25) Then
        Call FreezeMe
    End If
End Sub

Thank you very much,
the codes is working and this solves my problem. but with this i faced a new one, could you please also help me to lock the coding page (if this is possible), as if anyone open the VB coding page the password is visible there and he/se can un-protect the sheet.
 
click-tools-vbaproject-properties.png



upload_2015-7-30_16-43-57.png


http://www.excel-easy.com/vba/examples/protect-macro.html
 
Hi..

How to protect entire column when date changes...

suppose i have data from A to G ..

A = contains cust name and Fro B to G contains date from 10-march-2016 to 16 march -2016

now i want to restrict column B when 10 march is over then when 11 march is over then column B & C restrict to change data...

how to do this...
 
Back
Top