[求助][VBA]明细表输出
<P>我在论坛上下载了一段明细表输出为excel表格的程序,但程序有问题,执行不通,我以前没用过VBA。另外,我还想问问,我想用lisp实现绘图,但不知在VLISP怎么调用这段VBA代码,特请大家指教。代码如下:</P><P>我用的是EXCEL2003版本,CAD2006,引用选择的是<FONT face=宋体>"</FONT>Microsoft Excel 11.0 Object Library"</P>
<P>Dim ExcelApp As Excel.Application</P>
<P>'激活要与之通信的Excel应用程序</P>
<P>On Error Resume Next</P>
<P>Set ExcelApp = GetObject(, "Excel.Application")</P>
<P>If Err <> 0 Then</P>
<P>Set ExcelApp = CreateObject("Excel.Applicationn")</P>
<P>End If</P>
<P> <BR> Sub BlkAttr_Extract()<BR> Dim Excel As Excel.Application<BR> Dim ExcelSheet As Object<BR> Dim ExcelWorkbook As Object<BR> '创建Excel应用程序实例<BR> On Error Resume Next<BR> Set Excel = GetObject(, "Excel.Application")<BR> If Err <> 0 Then<BR> Set Excel = CreateObject("Excel.Application")<BR> End If<BR> '创建一个新工作簿<BR> Set ExcelWorkbook = Excel.Workbooks.Add<BR> '确保Sheet1工作表为当前工作表<BR> Set ExcelSheet = Excel.ActiveSheet<BR> '将新创建的工作簿保存为Excel文件<BR> ExcelWorkbook.SaveAs "属性表.xls"<BR> '令Excel应用程序可见<BR> Dim RowNum As Integer<BR> Dim Header As Boolean<BR> Dim blkElem As AcadEntity<BR> Dim Array1 As Variant<BR> Dim Count As Integer<BR> RowNum = 1<BR> Header = False<BR> '遍历模型空间,查找明细表的每个块引用表行<BR> For bEach blkElem In ThisDrawing.ModelSpace<BR> With blkElem<BR> '当一个块引用表行被找到后,检查它是否有属性<BR> If StrComp(.EntityName, "AcDbBlockReference", 1) = 0 Then<BR> '如果有属性<BR> If .HasAttributes Then<BR> '提取块引用中的属性<BR> Array1 = .GetAttributes<BR> '这一轮循环用来查找标题,如果有填在第1行<BR> For Count = LBound(Array1) To UBound(Array1)<BR> '如果还没有标题<BR> If Header = False Then<BR> '作为标题的明细行其块属性常设为Constant类型<BR> If Array1(Count).Constant Then<BR> ExcelSheet.Cells(RowNum, Count + 1).Value _<BR> = Array1(Count).TextString<BR> End If<BR> End If<BR> Next Count<BR> '从第2行开始,填写其它的明细表行内容<BR> RowNum = RowNum + 1<BR> For Count = LBound(Array1) To UBound(Array1)<BR> ExcelSheet.Cells(RowNum, Count + 1).Value _<BR> = Array1(Count).TextString<BR> Next Count<BR> Header = True<BR> End If<BR> End If<BR> End With<BR> Next blkElem<BR> '对填入当前表单的内容,按第1列进行排序,<BR> '范围是从A1单元格开始的整个工作表<BR> Excel.Worksheets("Sheet1").Range("A1").Sort _<BR> key1:=Excel.Worksheets("Sheet1").Columns("A"), _<BR> Header:=xlGuess<BR> '显示Excel工作表中的结果<BR> Excel.Visible = True<BR> '该语句用来等待查看显示结果<BR> MsgBox "按‘确定’键将关闭Excel的运行!"<BR> '保存传过来的数据<BR> ExcelWorkbook.Save<BR> '关闭Excel应用程序<BR> Excel.Application.Quit<BR> '删除Excel应用程序实例<BR> Set Excel = Nothing<BR>End Sub<BR></P>
页:
[1]