Consulting

Results 1 to 2 of 2

Thread: Solved: Noob question

  1. #1
    VBAX Regular
    Joined
    Mar 2009
    Posts
    25
    Location

    Solved: Noob question

    I've got following code that I cant seem to get to work. This is proablably very easy since I am very new at this VBA programming.

    Thanks!

    [VBA]Option Explicit
    Private Sub CommandButton1_Click()
    Dim ws As Worksheet
    Dim passw As String
    Dim confirmpassw As String
    passw = passwbox.Text

    For Each ws In Worksheets
    If ws.ProtectContents = True Then
    ws.Unprotect Password:=passwbox.Text


    Else

    confirmpassw = InputBox("Confirm your password by re-entering:", "Password confirmation")
    If passw <> confirmpassw Then
    MsgBox ("Passwords does not match! Please try again.")
    Else
    ws.protect Password:=passw
    End If
    End If
    Unload Me
    Next ws

    End Sub[/VBA]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You don't say what is not working, but perhaps you are unloading the form too early, try doing after the Next ws.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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