Workbook should not open - code require
Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: Workbook should not open - code require
Thanks Thanks: 0 Likes Likes: 0

  1. #11
    Board Regular
    Join Date
    Apr 2010
    Posts
    167
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Workbook should not open - code require

    Quote Originally Posted by VBABEGINER View Post
    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 by Steve_; Jul 19th, 2019 at 12:48 PM.

  2. #12
    Board Regular
    Join Date
    Jun 2011
    Location
    Mumbai, Maharashtra,India.
    Posts
    1,091
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Workbook should not open - code require

    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..

    Quote Originally Posted by sykes View Post
    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.

  3. #13
    Board Regular
    Join Date
    Jun 2011
    Location
    Mumbai, Maharashtra,India.
    Posts
    1,091
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Workbook should not open - code require

    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..

    Quote Originally Posted by Steve_ View Post
    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

  4. #14
    Board Regular
    Join Date
    Jun 2011
    Location
    Mumbai, Maharashtra,India.
    Posts
    1,091
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Workbook should not open - code require

    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..

    Quote Originally Posted by Steve_ View Post
    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 by VBABEGINER; Jul 29th, 2019 at 12:28 PM.

  5. #15
    Board Regular
    Join Date
    Apr 2010
    Posts
    167
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Workbook should not open - code require

    Quote Originally Posted by VBABEGINER View Post
    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.

  6. #16
    Board Regular
    Join Date
    Jun 2011
    Location
    Mumbai, Maharashtra,India.
    Posts
    1,091
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Workbook should not open - code require

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

    Quote Originally Posted by Steve_ View Post
    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.

  7. #17
    Board Regular
    Join Date
    Jun 2011
    Location
    Mumbai, Maharashtra,India.
    Posts
    1,091
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Workbook should not open - code require

    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

    Quote Originally Posted by VBABEGINER View Post
    Sure please.. I would like to see the updated code..

  8. #18
    Board Regular
    Join Date
    Apr 2010
    Posts
    167
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Workbook should not open - code require

    Quote Originally Posted by VBABEGINER View Post
    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

  9. #19
    Board Regular
    Join Date
    Jun 2011
    Location
    Mumbai, Maharashtra,India.
    Posts
    1,091
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Workbook should not open - code require

    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

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •