Option
Explicit
Private
Sub
TextBox1_KeyDown(
ByVal
KeyCode
As
MSForms.ReturnInteger,
ByVal
Shift
As
Integer
)
If
getCountLines(
Me
.TextBox1.Text) >= 3
Then
If
KeyCode = 13
Then
KeyCode = 0
End
If
End
If
End
Sub
Function
getCountLines(strText
As
String
)
Dim
iTMP
As
Integer
Dim
iCounter
As
Integer
Dim
iStart
As
Integer
iStart = 1
iCounter = 1
Do
iTMP = InStr(iStart, strText, vbCr)
iStart = IIf(iTMP > 0, iTMP + 1, iStart)
iCounter = iCounter + IIf(iTMP > 0, 1, 0)
Loop
While
iTMP > 0
getCountLines = iCounter
End
Function