Firstly, please post your code by using the toolbar button "</>" above the message window, so that the code is easily readable.
It seems you want user to keep select TEXT/MTEXT entities to update their TextString until user wants to stop. All CAD user knows to hits ESC key to stop data entering or entity/point/distance picking. So, in your code, if you do nothing, user can always hit Esc to stop, which may break your code, depending on the VBA setup (stop at all error, or only not handled error).
Also, it seems you pick an arbitrary number (50) to allow the loop goes to maximum 50 times, which is a very bad practice.
Following code shows how to do it correctly:
1. You use a do...loop while() to allow use to pick as many time as he/she wants;
2. in the picking method, also use a do...loop while() to ask user to pick at least once. User could hits ESC, or could enter keywork (to exit, in this case), or could select a wrong type of entity (e.g. not Text/MText). If first 2 cases, the code exits from loop and return a Nothing, meaning, user wants to stop the while thing. Only user selects a TEXT/MText, the code exit the loop and return a valid entity back, so the main loop would update the selected TEXT/MTEXT; then go on for user to pick next TEXT/MTEXT.
Option Explicit
Public Sub UpdatePickedTextEntities()
Dim ent As AcadEntity
Dim entText As AcadText
Dim entMText As AcadMText
Dim text As String
text = "XXXXXXXXXXXXXXXXXXXX"
Do
Set ent = SelectTextEntity()
If ent Is Nothing Then Exit Do
If TypeOf ent Is AcadText Then
Set entText = ent
entText.TextString = text
ElseIf TypeOf ent Is AcadMText Then
Set entMText = ent
entMText.TextString = text
End If
Loop While (True)
End Sub
Private Function SelectTextEntity() As AcadEntity
Dim ent As AcadEntity
Dim pt As Variant
Dim errDesc As String
Dim keywords As String
keywords = "eXit"
On Error Resume Next
ThisDrawing.Utility.InitializeUserInput 128, keywords
'' use a loop, so that if select a wrong type of entity,
'' we only loop back to ask user to re-seelct
Do
ThisDrawing.Utility.GetEntity ent, pt, vbCr & "Select TEXT/MEXT entity or [eXit]: "
If Err Then
errDesc = Err.Description
If StrComp(errDesc, "User input is a keyword") = 0 Then
''User entered a keyword
'' If there are multiple keyworkds, you would do
'' something differently/accordingly
Else
'' User hits ESC, do something is neceaary
End If
'' in this particular case, whether use hits Esc, or enter the keywork
'' we just want to stop the picking
Exit Do
End If
If TypeOf ent Is AcadText Or TypeOf ent Is AcadMText Then Exit Do
Loop While (True)
Set SelectTextEntity = ent
End Function
HTH