Workbook should not open - code require

Steve_

Board Regular
Joined
Apr 28, 2010
Messages
167
Hi Steve.. pls give me solution about password.. my entire work in that file.. it is not opening now..

When you are asked to 'Enter PAssword', hit CTRL+BREAK on your keyboard.


Replace the code with this..


Code:
Private Sub Workbook_Open()
    Correct_Password = "test"               ' Set this to the password you want.
    myDate = "7/19/2019 8:21:22 AM"  ' Set this to the date/time you want
    doOpen = False: aFail = 0 
    If myDate > Now Then 
        Do Until doOpen 
            uPwd = InputBox("Enter Password", "Authentication Required")
            If uPwd = Correct_Password Then
                doOpen = True
            End If
            Select Case doOpen
                Case True
                    Exit Sub
                Case Else
                    aFail = aFail + 1
                    If aFail >= 3 Then
                        Application.DisplayAlerts = False
                        ThisWorkbook.Close
                    End If
            End Select
        Loop
    End If
End Sub
 
Last edited:

Some videos you may like

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,130
HI Sykes.. Thank you so much for your reply. i was on leave for entire week. I tried Steve's trick and it works.. Thanks again..

ALWAYS test on a copy of your treasured work, FIRST!

In case Steve's off line for a while.....
Can you open your Excel application, go into macro security, and set it to disable all macros, or at least "Ask before opening" then try and open the workbook without the macros running? This should allow you to access the code, and disable the problem.
 

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,130
Hi Steve, Thank you so much for your time and reply.. The trick Ctr+break works fabulous. Thanks for this.. and really appreciate you that you have given me solution.. This is the specialty of Mrexcel..

Hats off guys..

The password should simply be blank unless you set it to something.

Either way, when it prompts you for the password, hit ctrl+break.

My guess here is that you either did not set a password or you did not write code to set doOpen to true when the correct password is provided
 

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,130
HI.. sorry, there is one more solution, sykes.. he too given me solution.. so that too work.. Thanks..
----
Hi Steve..
I tried ur these code. I keep today date i.e 7/29/2019 but still it asking me for password window.. it should not ask me for the same day.. If your able to give me solution then provide else Okk.. whatever you replied till that really thankfull..

When you are asked to 'Enter PAssword', hit CTRL+BREAK on your keyboard.


Replace the code with this..


Code:
Private Sub Workbook_Open()
    Correct_Password = "test"               ' Set this to the password you want.
    myDate = "7/19/2019 8:21:22 AM"  ' Set this to the date/time you want
    doOpen = False: aFail = 0 
    If myDate > Now Then 
        Do Until doOpen 
            uPwd = InputBox("Enter Password", "Authentication Required")
            If uPwd = Correct_Password Then
                doOpen = True
            End If
            Select Case doOpen
                Case True
                    Exit Sub
                Case Else
                    aFail = aFail + 1
                    If aFail >= 3 Then
                        Application.DisplayAlerts = False
                        ThisWorkbook.Close
                    End If
            End Select
        Loop
    End If
End Sub
 
Last edited:

Steve_

Board Regular
Joined
Apr 28, 2010
Messages
167
HI.. sorry, there is one more solution, sykes.. he too given me solution.. so that too work.. Thanks..
----
Hi Steve..
I tried ur these code. I keep today date i.e 7/29/2019 but still it asking me for password window.. it should not ask me for the same day.. If your able to give me solution then provide else Okk.. whatever you replied till that really thankfull..
So the reason for this is that the myDate is being set to the second.

We can trim that down if you need. Is this still an issue? If so I can whip you up a quick upgrade in about 3 minutes.
 

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,130
Sure please.. I would like to see the updated code..

So the reason for this is that the myDate is being set to the second.

We can trim that down if you need. Is this still an issue? If so I can whip you up a quick upgrade in about 3 minutes.
 

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,130
Sorry both but both your code is not working..

even though i have place tomorrow date - 8/7/2019
or
in cell - 8/7/2019

both cases it asking me password.. Password prompt should only popped up when date mentioned in code is smaller than today's date.

suppose if i try to open file after 07 Aug, it should then ask me password prompt

Sure please.. I would like to see the updated code..
 

Steve_

Board Regular
Joined
Apr 28, 2010
Messages
167
Sorry both but both your code is not working..

even though i have place tomorrow date - 8/7/2019
or
in cell - 8/7/2019

both cases it asking me password.. Password prompt should only popped up when date mentioned in code is smaller than today's date.

suppose if i try to open file after 07 Aug, it should then ask me password prompt

Try this.

Code:
Private Sub Workbook_Open()
    Dim myDate As Date
    Correct_Password = "test"               ' Set this to the password you want.
    myDate = "8/7/2019"  ' Set this to the date/time you want
    doOpen = False: aFail = 0
    If myDate < Format(Now, "mm/dd/yyyy") Then
        Do Until doOpen
            uPwd = InputBox("Enter Password", "Authentication Required")
            If uPwd = Correct_Password Then
                doOpen = True
            End If
            Select Case doOpen
                Case True
                    Exit Sub
                Case Else
                    aFail = aFail + 1
                    If aFail >= 3 Then
                        Application.DisplayAlerts = False
                        ThisWorkbook.Close
                    End If
            End Select
        Loop
    End If
End Sub
 

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,130
i modified this..
Code:
Private Sub Workbook_Open()
s1 = Date
If Sheets("Sheet1").Range("Z1").Value = s1 Then Exit Sub
If InputBox("Password please", "Password check") <> "Password" Then Me.Close (False)
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,102,782
Messages
5,488,850
Members
407,658
Latest member
Arias610

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top