Dim acadApp As AcadApplication Dim acadDoc As AcadDocument Sub ConnectToAcad() On Error Resume Next Set acadApp = GetObject(, "AutoCAD.Application") If Err Then Err.Clear Set acadApp = CreateObject("AutoCAD.Application") acadApp.Visible = True If Err Then MsgBox Err.Description End If Set acadDoc = acadApp.ActiveDocument End Sub Private Sub Command1_Click() Dim start1(2) As Double Dim end1(2) As Double
end1(0) = 100 Dim line As AcadLine Call ConnectToAcad Set line = acadDoc.ModelSpace.AddLine(start1, end1) End Sub 上面的这样代码是没有问题可运行的,但版本只能限于我所在的版本(如2004版) 有朋友说 Dim acadApp As AcadApplication Dim acadDoc As AcadDocument 改为 Dim acadApp As Object Dim acadDoc As Object 问题是我一这样用就出错,为什么呢? |