Workbook should not open - code require

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,232
Hi All Board members,

Can any one please provide me code..

the excel file which i will share today with someone..should not open that workbook without password..

Pls assist..
 
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:
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
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.
 
Upvote 0
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
 
Upvote 0
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:
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
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..
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,218
Members
448,554
Latest member
Gleisner2

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