求助:帮忙修改一下cad中多段线坐标输出到excel
选择autocad中的pl线,然后将x和y坐标输出到excel当前激活单元格位置。麻烦高手帮忙改改吧,非常感谢。我根据网上的代码,修改了一下,可是偶尔可以运行成功。不知道问题出在哪里。
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
页:
[1]