Results 1 to 1 of 1

Thread: Excel macro mystery

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2000
    Posts
    35

    Question Excel macro mystery

    I have a couple of very simple excel macros for protecting and unprotecting a sheet. They work fine if yoy run them by means of a hotkey but give an error when a command button calls the code. Here's this code:

    Sub Prot()
    'Activate with ctrl/j
    Sheets(1).Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    MsgBox "Protected", vbOKOnly
    End Sub
    Sub Unprot()
    'Activate with ctrl/k
    Sheets(1).Unprotect
    MsgBox "Unprotected", vbOKOnly
    End Sub
    Sub CommandButton1_Click()
    Static i As Integer
    If i = 0 Then
    Prot
    Else
    Unprot
    End If

    I attach the spreadsheet if you want to try it out...
    It just doesn't make any sense. Maybe I have overlooked something!?
    Attached Files Attached Files

Posting Permissions

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



Click Here to Expand Forum to Full Width