明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 822|回复: 3

“AutoCAD.Application”未定义,求解

[复制链接]
发表于 2015-8-6 15:51:13 | 显示全部楼层 |阅读模式
上码先:
  1. Sub Drawline()
  2.    
  3.    Dim AutoCADApp As AutoCAD.Application
  4.    Set AutocadApp = CreateObject("AutoCAD.Application")
  5.    Dim Aline As AcadLine
  6.    Dim PointS(2) As Double
  7.    Dim PointE(2) As Double
  8.    
  9.    PointS(0) = ThisWorkbook.Sheets("Sheet1").Cells(2, 2).Value
  10.    PointS(1) = ThisWorkbook.Sheets("Sheet1").Cells(2, 3).Value
  11.    PointS(2) = ThisWorkbook.Sheets("Sheet1").Cells(2, 4).Value
  12.    
  13.    PointE(0) = ThisWorkbook.Sheets("Sheet1").Cells(3, 2).Value
  14.    PointE(1) = ThisWorkbook.Sheets("Sheet1").Cells(3, 3).Value
  15.    PointE(2) = ThisWorkbook.Sheets("Sheet1").Cells(3, 4).Value
  16.    
  17.    AutocadApp.Visible = True
  18.    Set Aline = AutocadApp.ModelSpace.AddLine(PointS, PointE)
  19.    Aline.Highlight = True

  20.    
  21. End Sub


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


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


烦请请各位指教!



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2015-8-7 11:07:36 | 显示全部楼层
发表于 2015-8-7 11:29:26 | 显示全部楼层
发表于 2015-8-7 11:55:07 | 显示全部楼层
  1. Sub drawline2()
  2. Dim acadApp As Object
  3. Dim acadDoc As Object
  4. On Error Resume Next
  5. Set acadApp = GetObject(, "AutoCAD.Application")
  6. If err Then
  7. err.Clear
  8. Set acadApp = CreateObject("AutoCAD.Application")
  9. If err Then End
  10. End If

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

  15.    PointS(0) = Cells(2, 2)
  16.    PointS(1) = Cells(2, 3)
  17.    PointS(2) = Cells(2, 4)

  18.    PointE(0) = Cells(3, 2)
  19.    PointE(1) = Cells(3, 3)
  20.    PointE(2) = Cells(3, 4)
  21.       
  22.    acadApp.Visible = True
  23.    Set Aline = acadDoc.ModelSpace.AddLine(PointS, PointE)
  24.    Aline.Highlight = True
  25.    'acadDoc.Application.ZoomExtents
  26. End Sub
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 10:06 , Processed in 0.170395 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表