Attribute VB_Name = "Excel2Acad" Option Explicit ' VBA for AutoCAD 2002: Writing AutoCAD Macros ' Jeffrey E. Clark ' Copyright 2002 Prentice Hall PTR ' This software may be freely copied and used so long as this disclaimer, ' together with the above copyright notice, are included in all copies and ' any accompanying documentation. These example programs are made available ' "as-is" without any explicit or implied warranty. Neither the author nor ' publisher warrant that these programs are error free or will operate ' without interruption. ' Example 1-2. Sub Main() Dim xAP As Excel.Application Dim xWB As Excel.Workbook Dim xWS As Excel.Worksheet Set xAP = Excel.Application Set xWB = xAP.Workbooks.Open("C:\A2K2_VBA\IUnknown.xls") Set xWS = xWB.Worksheets("Sheet1") MsgBox "Excel says: """ & Cells(1, 1) & """" Dim A2K As AcadApplication Dim A2KDwg As AcadDocument Set A2K = CreateObject("AutoCAD.Application") Set A2KDwg = A2K.Application.Documents.Add MsgBox A2K.Name & " version " & A2K.Version & " is running." Dim Height As Double Dim P(0 To 2) As Double Dim TxtObj As AcadText Dim TxtStr As String Height = 1 P(0) = 1: P(1) = 1: P(2) = 0 TxtStr = Cells(1, 1) Set TxtObj = A2KDwg.ModelSpace.AddText(TxtStr, P, Height) A2KDwg.SaveAs "C:\A2K2_VBA\IUnknown.dwg" A2K.Documents.Close A2K.Quit Set A2K = Nothing xAP.Workbooks.Close xAP.Quit Set xAP = Nothing End Sub