Thanks for your help !
Hereunder the code, most important lines are in bold.
Last question : once I the object is selected, how can I display its properties in the AutoCAD Properties dialog box ? Exactly like when I click on an object, its properties and grips are displayed. If I Highlight and Select the object (VBA), it is highlighted. It is also selected in VBA-side, but not in user-side.
Sub Find_object_by_field()
'Zoom on the object concerned by the selected field
Dim oSel As AcadSelectionSet
Dim oTxt As AcadMText
Dim oObjectId As Variant
Dim oObj As AcadObject
Dim ObjType As String
Dim txtField As String
Dim varPointMin As Variant
Dim varPointMax As Variant
Dim point1(0 To 2) As Double
Dim point2(0 To 2) As Double
Const cstMargeZoom = 0.6
On Error Resume Next
ThisDrawing.SelectionSets("oSel").Delete
On Error GoTo 0
ThisDrawing.SelectionSets.Add ("oSel")
Set oSel = ThisDrawing.SelectionSets("oSel")
'Select the object
oSel.SelectOnScreen
Set oObj = oSel(0)
ObjType = TypeName(oObj)
'Test if the selected object is a Text or MText
if ObjType = "IAcadText" Or ObjType = "IAcadMText" Then
txtField = oObj.FieldCode
MsgBox (txtField)
Else
MsgBox ("Select a text")
Exit Sub
End If
'From the text, extract the Object Id
varObjId = Val(Split(Split(txtField, "_ObjId")(1), ">")(0))
'Find the object
For Each objacad In ThisDrawing.ModelSpace
If objacad.ObjectID = varObjId Then
ReDim ssobjs(0) As AcadEntity
Set ssobjs(0) = objacad
oSel.AddItems ssobjs
oSel.Highlight (True)
'Zoom on the object
objacad.GetBoundingBox varPointMin, varPointMax
point1(0) = varPointMin(0)
point1(1) = varPointMin(1)
point1(2) = 0
point2(0) = varPointMax(0)
point2(1) = varPointMax(1)
point2(2) = 0
ZoomWindow point1, point2
ZoomScaled cstMargeZoom, acZoomScaledRelative
Exit For
End If
Next objacad
End Sub