Lock all the controls in a userform

NDMDRB

Board Regular
Joined
Jun 20, 2016
Messages
164
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have a userform with many Textboxes, Labels, CommandButtons....

I need to lock all the controls when the userform Initializes

Instead of locking each control separate, I found this code on google that works well if the userform doesn't contain any label, else if there is any label, there will be an error

Code:
Private Sub UserForm_Initialize()
Dim ctrl As Control
For Each ctrl In Box.Frame1.Controls
ctrl.Locked = True
Next
Set ctrl = Nothing

Me.cmd_New.Locked = False


End Sub

Can someone please tell me how to fix this code to lock all the controls in the userform even if it contains labels?
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
If you look at the Label control Properties you will see there is no Locked.
You can Enable a label or Inable a label but you cannot lock a label.
 
Last edited:
Upvote 0
Ow thank you, so I have to replace "Locked" with Enabled"
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,576
Members
448,972
Latest member
Shantanu2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top