Hi Tom, this is copied from above mentioned thread.
Hope that it helps.
Marko.
------------
Gary, the reason, why the code that you find on
this ng doesn't work "out of the box", is that this are usually just pieces of
the code and normally you have to add a few pieces by yourself for the code
to come to life. Try the following.
1. Open VBA window under an AutoCAD and add a new
UserForm.
2. Then add standard Module.
3. Go to the standard Module and copy to it the
following lines of code from the example:
Option
Explicit
Public
Declare Function GetAsyncKeyState Lib "user32" _
(ByVal vKey As Long) As Integer
Public Const
VK_ESCAPE = &H1B
Public Const
VK_LBUTTON = &H1
4. Then go to UserForm and add a Command Button and
name it cmdOK.
5. Switch to the Code view of the UserForm and add
the following function from the example:
Public
Function EntSel(strPrmt As String) As AcadEntity
Dim objTemp As
AcadEntity
Dim
objUtil As AcadUtility
Dim varPnt As Variant
Dim varCancel As
Variant
On Error
GoTo Err_Control
Set
objUtil = ThisDrawing.Utility
objUtil.GetEntity objTemp, varPnt,
strPrmt
Set EntSel =
objTemp
Exit_Here:
Exit
Function
Err_Control:
Select
Case Err.Number
Case
-2147352567
varCancel =
ThisDrawing.GetVariable("LASTPROMPT")
If InStr(1, varCancel, "*Cancel*") <> 0
Then
If GetAsyncKeyState(VK_ESCAPE)
And 8000 > 0
Then
Err.Clear
Resume
Exit_Here
ElseIf
GetAsyncKeyState(VK_LBUTTON) > 0
Then
Err.Clear
Resume
End
If
Else
'Missed the pick, send them
back!
Resume
End
If
Case
Else
MsgBox
Err.Description
Resume Exit_Here
End Select
End
Function
6. Go back to the Object view of your UserForm and
double click on a command button that you added two steps back. VBA will
automatically switch over to Code window and add initial part of code for your
command button. Add the following lines between the start and end of the sub so
that it looks like this:
Private Sub
cmdOK_Click()
Dim strPrmt As
String
Me.Hide
strPrmt = "Select object"
EntSel (strPrmt)
face=Arial size=2> Me.Show
End Sub
7. Well that's it basically, now your code should
work. If you still don't understand something it's most probably because I'm
also quite unfamiliar with VBA. Good luck.
------------