Sub a() '连接EXCEL——标准代码**************************** Dim xlApp As Excel.Application Dim xlbook As Excel.Workbook Dim xlSheet As Excel.Worksheet On Error Resume Next Set xlApp = GetObject(, "excel.application") If Err <> 0 Then Err.Clear Set xlApp = CreateObject("excel.application") If Err <> 0 Then MsgBox "无法启动excel" Exit Sub End If End If If ActiveWorkbook.Sheets.Count = 0 Then xlbook = xlApp.Workbooks.Add Set xlbook = xlApp.ActiveWorkbook Set xlSheet = xlbook.ActiveSheet xlApp.Visible = True If Err <> 0 Then Err.Clear '标准代码结束***************************************** Dim retCoord() As Double Dim a As AcadLWPolyline Dim i As Integer Dim j As Integer Dim l As Integer i = 0 ThisDrawing.Utility.GetEntity a, "Select an object" retCoord() = a.Coordinates On Error GoTo e Do While CBool(retCoord(i)) <> False j = ActiveCell.Row '这个无法返回激活单元格地址 l = ActiveCell.Column xlSheet.Cells(j + i / 2, l).Value = retCoord(i) xlSheet.Cells(j + i / 2, l + 1).Value = retCoord(i + 1) i = i + 2 Loop e: Exit Sub j = 0 l = 0 End Sub 以上是一个将cad中多段线点坐标导入excel中去的代码,在cad中运行该宏,电脑提示“用户定义类型未定义”(红色部分),这是怎么回事??哪位大侠能告诉我?? |