
下面我们就来解决上面提到的与CAD的连接和通讯问题。
进入VBAIDE,按[工具]->[引用],找到可使用的引用,在“AutoCAD2000类型库”的左边打钩,点确定就行了。在模块中输入以下代码:
Global Sheet As Object, acadmtext As acadmtext, fontHight As Double
Global xlBook As Excel.Workbook
Global p0(2) As Double, p1(2) As Double, p2(2) As Double
Global acadApp As AcadApplication
Global acadDoc As AcadDocument
Global acadPoint As acadPoint
Global number As Integer
Public Type pt
n As Integer
pt(2) As Double
Global pt() As pt
Global text1 As AcadText
Global CAD As Object
Global p(2) As Double, i As Integer, j As Integer
Global h As Integer, l As Integer
Public Function Get_ACAD(Dwt As String) As Boolean
Dim YER As Integer
On Error Resume Next
Set acadApp = GetObject(, "AutoCAD.Application")
If Err Then
Err.Clear
Set acadApp = CreateObject("AutoCAD.Application")