+ Reply to Thread
Results 1 to 2 of 2

Macro does not work when sheet is protected?? Please Help

  1. #1
    Registered User
    Join Date
    07-11-2011
    Location
    Delhi, India
    MS-Off Ver
    Excel 2007
    Posts
    26

    Macro does not work when sheet is protected?? Please Help

    Hi All, Hi tigeravatar

    Below is the code of one of the macros, the problem is it does now work when the work sheet is passowrd protected?? can somebody help? Password to unlock the sheet is "international". I want the macro to open the sheet paste the details and then again lock the sheet...somebody please help?



    Sub btn_Submit_Click()

    Dim wsReq As Worksheet 'Request worksheet (Request Form)
    Dim wsSch As Worksheet 'Schedule worksheet (Only to be seen by Admin)
    Dim rngFindName As Range
    Dim rIndex As Long
    Dim strName As String

    Set wsReq = ActiveSheet
    Set wsSch = Sheets("Only to be seen by Admin")

    With wsReq
    If Trim(.Range("C7").Value) = vbNullString Then
    .Range("C7:D8").Select
    MsgBox "No employee code provided.", , "Shift Request Error"
    Exit Sub
    End If

    Set rngFindName = wsSch.Columns("C").Find(.Range("C7").Value, , , xlWhole)
    If Not rngFindName Is Nothing Then
    rIndex = rngFindName.Row
    strName = Trim(.Range("I6").Value)
    If strName = vbNullString Then strName = "(-)"
    wsSch.Cells(rIndex, Columns.Count).End(xlToLeft).Offset(, 1).Resize(, 6).Value = _
    Array(.Range("C10").Text, .Range("F10").Text, .Range("C16").Value, .Range("C19").Value, strName, .Range("C23").Value)
    .Range("C4:E5,C7:D8,C10:D11,C13:D14,C16:D17,C19:D20,C23:L26,F10:G11,I6:K7,J10:K11,J14:K15").ClearCon tents
    .Range("C4:E5").Select
    Else
    .Range("C7:D8").Select
    MsgBox "Employee Code [" & .Range("C7").Value & "] not found.", , "Shift Request Error"
    End If
    End With

    End Sub

    cheers and thanks

  2. #2
    Forum Contributor
    Join Date
    06-09-2011
    Location
    Germany
    MS-Off Ver
    Excel 2016
    Posts
    194

    Re: Macro does not work when sheet is protected?? Please Help

    Hi,

    just try to insert the two lines (wsSch.unprotect "international" and wsSch.protect "international" )
    and it should work (untestested)

    Please Login or Register  to view this content.
    Regards

    Theo

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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