Lock all the controls in a userform

NDMDRB

Board Regular
Joined
Jun 20, 2016
Messages
140
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?
 

Some videos you may like

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
16,760
Office Version
2013
Platform
Windows
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:

Watch MrExcel Video

Forum statistics

Threads
1,098,845
Messages
5,465,042
Members
406,409
Latest member
windiestboat

This Week's Hot Topics

Top