下面是根据你的要求写的一个VBA程序,房间面积的求法我不懂,你可以自己考虑一下。

- [FONT=courier new]
- Sub test()
- On Error Resume Next
- '创建选择集
- Dim SSetObj As AcadSelectionSet
- Set SSetObj = ThisDrawing.SelectionSets("Acad2Excel")
- If Err.Number <> 0 Then
- Err.Clear
- Set SSetObj = ThisDrawing.SelectionSets.Add("Acad2Excel")
- End If
- '清空选择集
- SSetObj.Clear
- '创建过过滤机制,只选择颜色为黄色的文本
- Dim fType(0 To 1) As Integer
- Dim fData(0 To 1) As Variant
- fType(0) = 0: fData(0) = "*Text"
- fType(1) = 62: fData(1) = acYellow
- SSetObj.Select acSelectionSetAll, , , fType, fData
- '如果没有选择到实体,则中断程序的运行
- If SSetObj.Count = 0 Then
- Set SSetObj = Nothing
- Exit Sub
- End If
- '启动Excel
- Dim xlApp As Object
- Set xlApp = GetObject(, "Excel.Application")
- If Err.Number <> 0 Then
- Err.Clear
- Set xlApp = CreateObject("Excel.Application")
- If Err.Number <> 0 Then
- Set SSetObj = Nothing
- MsgBox "无法启动 Excel97 或者 Excel200 !"
- Exit Sub
- End If
- End If
- '将Excel应用程序置为显示状态,默认为不显示。
- xlApp.Visible = True
- '启动一个新的Excel应用程序时,默认没有打开工作簿。
- If xlApp.Workbooks.Count = 0 Then xlApp.Workbooks.Add
- '添加一个新的工作表
- Dim xlSheet As Object
- Set xlSheet = xlApp.ActiveWorkbook.Worksheets.Add
- xlSheet.Range("B2") = "房间名"
- xlSheet.Range("C2") = "面积"
- Dim i As Integer
- For i = 0 To SSetObj.Count - 1
- xlSheet.Range("A3").Offset(i, 0) = i + 1
- xlSheet.Range("B3").Offset(i, 0) = SSetObj(i).TextString
- xlSheet.Range("C3").Offset(i, 0) = "" '这里添加房间面积
- Next
- Set SSetObj = Nothing
- Set xlSheet = Nothing
- Set xlApp = Nothing
- End Sub
- [/FONT]
|