Code can not run in Toolbar

Code can not run in Toolbar

hieut1392
Enthusiast Enthusiast
217 Views
1 Reply
Message 1 of 2

Code can not run in Toolbar

hieut1392
Enthusiast
Enthusiast

I am creating a macro that displays the name of a block by selecting an object. When I run the code in the VBA Editor, there is no problem (image 1). But when I add my macro to a custom toolbar, the code understands that the object is not selected, when I click on the icon on the toolbar and the code flies straight to line 13. (image 2). Can anyone help me?

 

hieut1392_0-1729092780222.png

 

hieut1392_1-1729092852165.png

 

 

 

 

 

Option Explicit

Sub GetBlockName()

    Dim blkRef As AcadBlockReference
    Dim obj As Object
    Dim pt(0 To 2) As Double
    Dim blockName As String

    On Error Resume Next
    ThisDrawing.Utility.GetEntity obj, pt, "Pick a block"
    If Err <> 0 Then
        MsgBox "No block", vbExclamation, "Error"
        Exit Sub
    End If
    If TypeOf obj Is AcadBlockReference Then
        Set blkRef = obj
        blockName = blkRef.Name
        MsgBox "Block name: " & blockName, vbInformation, "Name Block"
    Else
        MsgBox "Not Block!", vbExclamation, "Error"
    End If
    
End Sub

 

 

 

 

 

 

 

0 Likes
218 Views
1 Reply
Reply (1)
Message 2 of 2

Ed__Jobe
Mentor
Mentor

What is your toolbar macro?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes