Locking the TextBox for Editing?
Yes. it is possible.
Just set the .Locked
Property to True
Locking/Coloring just the first line or part of a text in textBox?
No. It is not possible in VBA. For partial coloring, you may want to use RichTextBox
in lieu of TextBox
but then again you will not be able to partially lock the control.
Edit
Alternative: Since the first line of text contains text that shouldn't be edited then why not show that info in a ToolTip
using the .ControlTipText
property of the TextBox
or say a Label
which displays when you hover the mouse on top of the TextBox
?
For example (Using the .ControlTipText
property)
Option Explicit
'~~> This is what goes in the tooltip. Amend as applicable.
Const sMsg As String = "Hello World! This is an example of tooltip text"
Private Sub UserForm_Initialize()
Dim sSample As String
Dim i As Long
For i = 1 To 10
sSample = sSample & "Blah Blah" & i & vbNewLine
Next i
TextBox1.Text = sSample
'~~> Set to starting point
TextBox1.SelStart = 0
End Sub
Private Sub TextBox1_MouseMove(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
TextBox1.ControlTipText = sMsg
End Sub
And now when you hover the text on top of the TextBox, you will be shown the ToolTip