Message 1 of 2
Code can not run in Toolbar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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?
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