28 | 04 | 2017

Open AutoCad file by Excel macro

The routine below opens a AutoCad file even if AutoCad is closed.

Sub main()
'***********************************
'*** Code From VisibleVisual.com ***
'***********************************
Dim ACAD As Object
Dim NewFile As Object
Dim MyAcadPath As String
Dim bReadOnly As Boolean

On Error Resume Next
ACAD = GetObject(, "ACAD.Application")
If (Err.Number <> 0) Then
   Err.Number = 0
    ACAD = CreateObject("autocad.Application")
   If (Err <> 0) Then
      MsgBox "Could Not Load AutoCAD!", vbExclamation, "Message"
      End
        End If
   End If
'If you want to see AutoCAD on screen
 'ACAD.Visible = True
MyAcadPath = "c:\Temp\Drawing2.dwg"
bReadOnly = True
NewFile = ACAD.Documents.Open(MyAcadPath, bReadOnly)

If (NewFile Is Nothing) Then
ErrorMessage:
    If NewFile = "False" Then End
    MsgBox ("Could not find the required spreadsheet that should be located at" & vbCr & MyAcadPath & vbCr & "Please rename or relocate the specified file as needed.")
   End
End If

 'Close AutoCAD Process
 'ACAD.Quit

ACAD = Nothing
NewFile = Nothing

End Sub
Login

Sign up now and upload your code to the website.

Help us to continue.....
Statistics
Articles View Hits
2236262
Latest Articles