Private Sub GetBlockCnt()
Dim Sheet As Worksheet
Dim ACad As Object
Dim ACadDwg As Object
Dim sPath As String
Dim ssetObj As Object
Dim mode As Integer
Dim gpCode(0) As Integer
Dim dataValue(0) As Variant
Dim I As Integer
Dim groupCode As Variant, dataCode As Variant
Const SELSET = "SSblockCnt"
Const acSelectionSetAll = 5
sPath = "c:\block_cnt.dwg"
Set ACad = GetObject(, "AutoCAD.Application")
If Err <> 0 Then
MsgBox "Please open a drawing file and then restart this macro."
Exit Sub
End If
Set ACadDwg = ACad.Application.Documents.Open(sPath)
For I = 0 To ACadDwg.SelectionSets.Count - 1
If ACadDwg.SelectionSets.Item(I).Name = SELSET Then
ACadDwg.SelectionSets.Item(I).Delete
End If
Next
Set ssetObj = ACadDwg.SelectionSets.Add(SELSET)
mode = acSelectionSetAll
gpCode(0) = 0
dataValue(0) = "INSERT"
groupCode = gpCode
dataCode = dataValue
ssetObj.Select mode, , , groupCode, dataCode
Set Sheet = ThisWorkbook.Sheets(1)
Sheet.Cells(1, 1) = sPath
Sheet.Cells(1, 2) = ssetObj.Count
ssetObj.Delete
ACadDwg.Close False
Set ssetObj = Nothing
Set ACadDwg = Nothing
Set ACad = Nothing
End Sub