Results 1 to 9 of 9

error with MsgBox

Threaded View

  1. #1
    Registered User
    Join Date
    03-21-2009
    Location
    Bangalore
    MS-Off Ver
    Excel 2003
    Posts
    60

    error with MsgBox

    Hi Friends,

    I worte a procedure to protect the worksheet. When we clik on command button it asks the password but if I click on cancel button procedure is exiting.

    Please help me with this code.

    Private Sub CommandButton1_Click()
    Dim pword As String
    Dim msg As String
    Dim ans As Integer
    
    TryAgain:
        ' Set up error handling if the entered password is wrong then control goes to the BadEntry label.
        On Error GoTo BadEntry
        'Assigned inputbox function to pword variable
        pword = InputBox("Enter the password", "Unlock the source sheet")
           
        'checks for password to unprotect the sheet
        If pword = "sadc" Then
            Sheets("source").Unprotect pword
        Exit Sub
        End If
    
    BadEntry:
        'Assigned msgbox information to msg variable
        msg = "Wrong Password, Try again?"
        'Assigned msgbox information to ans variable
        ans = MsgBox(msg, vbYesNo, "Information")
        If ans = vbNo Then
           Exit Sub
        End If
        'It checks weather user selected yes or no command butoons if the user selected "Yes"
         'then the control goes to AryAgrain label.
        If ans = vbYes Then GoTo TryAgain
            
         'Then Resume TryAgain
    'Exit Sub
    End Sub
    Thans and Regards
    Ramesh
    Last edited by ramserp; 12-10-2009 at 07:03 AM. Reason: to make title SOLVED

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1