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

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
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,430
Messages
6,119,453
Members
448,898
Latest member
drewmorgan128

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