View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sunil Pradhan[_2_] Sunil Pradhan[_2_] is offline
external usenet poster
 
Posts: 13
Default Macro Not working in Shared workbook

I have following vba code in excelworksheet. but i am getting run time error
1004 - method unprotect of object '_worksheet' failed while using it. Please
advise how i will be able to run these codes in shared workbook.



Private Sub btn_start_click()
mystartrow = 11
Do While Sheet1.Cells(mystartrow, 5).Value < ""
If mystartrow = 35 Then
Exit Sub
End If

If Sheet1.Cells(mystartrow, 5).Value < "" Then
mystartrow = mystartrow + 1
End If
Loop
Sheet1.Unprotect "protection"
Sheet1.Cells(mystartrow, 5) = (Now())
btn_start.Enabled = False
btn_end.Enabled = True
Sheet1.Protect "protection"
End Sub
Private Sub btn_end_click()
myendrow = 11
Do While Sheet1.Cells(myendrow, 6).Value < ""
If myendrow = 35 Then
Exit Sub
End If

If Sheet1.Cells(myendrow, 6).Value < "" Then
myendrow = myendrow + 1
End If
Loop
Sheet1.Unprotect "protection"
Sheet1.Cells(myendrow, 6) = (Now())
btn_end.Enabled = False
btn_start.Enabled = True
Sheet1.Protect "protection"
End Sub