Hi,
I am currently working on 51 spreadsheets each having various form controls. Especially my list box (from Form controls) resizes and also moves to different cells. I want to lock all sheets with various form controls. The option from "Format control >> Properties" Don't move or size with cells is not working. I found following code in the forum, and this is returning error "Compilation error, Invalid use of Me keyword". I changed from TextBox to ListBox and also tried changing locked to Enabled, but it is not working. Can anyone please help to resolve the issue or provide any new VBA code.
The Code I am using is:
Private Sub Form_Current()
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
ctrl.Locked = True
End If
Next
End Sub
to unlock
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
ctrl.Locked = False
End If
Next
End Sub
I am currently working on 51 spreadsheets each having various form controls. Especially my list box (from Form controls) resizes and also moves to different cells. I want to lock all sheets with various form controls. The option from "Format control >> Properties" Don't move or size with cells is not working. I found following code in the forum, and this is returning error "Compilation error, Invalid use of Me keyword". I changed from TextBox to ListBox and also tried changing locked to Enabled, but it is not working. Can anyone please help to resolve the issue or provide any new VBA code.
The Code I am using is:
Private Sub Form_Current()
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
ctrl.Locked = True
End If
Next
End Sub
to unlock
CODE
Private Sub UnlockButton_Click()Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
ctrl.Locked = False
End If
Next
End Sub