VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Code can not run in Toolbar

1 REPLY 1
Reply
Message 1 of 2
hieut1392
165 Views, 1 Reply

Code can not run in Toolbar

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

 

 

 

 

 

 

 

1 REPLY 1
Message 2 of 2
ed57gmc
in reply to: hieut1392

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report