- 积分
- 4764
- 明经币
- 个
- 注册时间
- 2007-12-16
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
选择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
|
|