wlh9421 发表于 2011-1-15 22:56:38

谁来帮帮我:未找到主键!!!!!!!!

Sub aa()
Dim a As Object
Dim b As Object
Dim c As Object
Dim sset As AcadSelectionSet
Dim filterType(0) As Integer, filterData(0) As Variant
Set a = CreateObject("excel.application")
Set b = a.Workbooks.Add
Set c = b.Worksheets(1)
If Not IsNull(ThisDrawing.SelectionSets.Item("ToExcel")) Then
   Set sset = ThisDrawing.SelectionSets.Item("ToExcel")
   sset.Delete
End IfSet sset = ThisDrawing.SelectionSets.Add("ToExcel")
filterType(0) = 0
filterData(0) = "line,circle,point"
sset.SelectOnScreen filterType, filterData
c.range("A1") = "ObjectCount" '写入标题
c.range("B1") = sset.Count       '写入数据
Dim Obj As AcadEntity, i As Long, varCP As Variant
   i = 2
   For Each Obj In sset
Select Case Obj.ObjectName
    Case "AcDbPoint"
    dd = Obj.Coordinates
   c.range(("A" & i)) = i - 1 '写入对象名
    c.range(("B" & i)) = dd(0)
    c.range(("C" & i)) = dd(1)
    c.range(("D" & i)) = dd(2)
      End Select
i = i + 1
   Next
a.Visible = True
End Sub
上次问过有位仁兄说红色部分缺少,所以加上,但是用的时候还是提醒未找到主键,有的时候却可以正常运行,为什么?

雪山飞狐_lzh 发表于 2011-1-16 12:30:47

on error resume next
ThisDrawing.SelectionSets("ToExcel").Delete
Set sset = ThisDrawing.SelectionSets.Add("ToExcel")

wlh9421 发表于 2011-1-16 13:29:53

回复 雪山飞狐_lzh 的帖子

还有为什么有的时候能执行,有的时候执行不了,还有主键是什么意思,可以通俗的说下不|?》?先谢过了
页: [1]
查看完整版本: 谁来帮帮我:未找到主键!!!!!!!!