poople 发表于 2015-8-6 15:51:13

“AutoCAD.Application”未定义,求解

上码先:
Sub Drawline()
   
   Dim AutocadApp As AutoCAD.Application
   Set AutocadApp = CreateObject("AutoCAD.Application")
   Dim Aline As AcadLine
   Dim PointS(2) As Double
   Dim PointE(2) As Double
   
   PointS(0) = ThisWorkbook.Sheets("Sheet1").Cells(2, 2).Value
   PointS(1) = ThisWorkbook.Sheets("Sheet1").Cells(2, 3).Value
   PointS(2) = ThisWorkbook.Sheets("Sheet1").Cells(2, 4).Value
   
   PointE(0) = ThisWorkbook.Sheets("Sheet1").Cells(3, 2).Value
   PointE(1) = ThisWorkbook.Sheets("Sheet1").Cells(3, 3).Value
   PointE(2) = ThisWorkbook.Sheets("Sheet1").Cells(3, 4).Value
   
   AutocadApp.Visible = True
   Set Aline = AutocadApp.ModelSpace.AddLine(PointS, PointE)
   Aline.Highlight = True

   
End Sub


这段代码是在Excel VBA环境下编写的,目的是将Excel表格中的两个点的数据传递到AutoCAD中并画出直线。
代码运行至第一句“Dim AutocadApp As AutoCAD.Application”就卡主了,提示如下:


然而,在运行这段代码前我已经加载了“AutoCAD 2008 Type library”库:


烦请请各位指教!



yuanziyou 发表于 2015-8-7 11:07:36

http://bbs.mjtd.com/thread-81422-1-1.html

zzyong00 发表于 2015-8-7 11:29:26

http://bbs.mjtd.com/thread-111783-1-1.html

yuanziyou 发表于 2015-8-7 11:55:07

Sub drawline2()
Dim acadApp As Object
Dim acadDoc As Object
On Error Resume Next
Set acadApp = GetObject(, "AutoCAD.Application")
If err Then
err.Clear
Set acadApp = CreateObject("AutoCAD.Application")
If err Then End
End If

Set acadDoc = acadApp.ActiveDocument
   Dim Aline As Object
   Dim PointS(2) As Double
   Dim PointE(2) As Double

   PointS(0) = Cells(2, 2)
   PointS(1) = Cells(2, 3)
   PointS(2) = Cells(2, 4)

   PointE(0) = Cells(3, 2)
   PointE(1) = Cells(3, 3)
   PointE(2) = Cells(3, 4)
      
   acadApp.Visible = True
   Set Aline = acadDoc.ModelSpace.AddLine(PointS, PointE)
   Aline.Highlight = True
   'acadDoc.Application.ZoomExtents
End Sub
页: [1]
查看完整版本: “AutoCAD.Application”未定义,求解