Welcome to AUGI. Please post your code using CODE tags. To to this, click on the Go Advanced button when you are posting. Then highlight your code and click on the Hashtag # button. This willl surround your code with tags.
It is entirely possible to get the Handle and Object ID's of a new entity using VBA. In the following sub, the ModelSpace.AddXXX functions return the object just added. Don't just add the entity, but use it to set a variable. Here I've added an MLeader object and at the end I print out the handle and objectName
Code:
Sub AddMLeader(ptcenter As Variant, txtpoint As Variant, Noofdigit As Integer) 'place coordinate with leader
Dim oML As AcadMLeader
Dim pts(0 To 5) As Double
Dim xText As String
Dim yText As String
Dim txtCoord As String
xText = digit(ptcenter(0), Noofdigit)
yText = digit(ptcenter(1), Noofdigit)
txtCoord = xText & " E" & vbCrLf & yText & " N"
' Define the leader points
pts(0) = ptcenter(0): pts(1) = ptcenter(1): pts(2) = ptcenter(2)
pts(3) = txtpoint(0): pts(4) = txtpoint(1): pts(5) = txtpoint(2)
Set oML = ThisDrawing.ModelSpace.AddMLeader(pts, 0)
oML.TextString = txtCoord 'show coordinate
oML.TextLeftAttachmentType = acAttachmentMiddle
oML.TextRightAttachmentType = acAttachmentMiddle
If ptcenter(0) > txtpoint(0) Then
oML.TextJustify = acAttachmentPointMiddleRight
'oML.TextDirection = acRightToLeft
Else
oML.TextJustify = acAttachmentPointMiddleLeft
End If
oML.Update
Debug.Print oML.ObjectID
Debug.Print oML.ObjectName
End Sub