How do I open an AutoCAD file from Excel?
How do I open an AutoCAD file from Excel?
(OP)
From Excel I want to use the GetOpenFilename method to open an Autocad file. Below is what I have but it certainly doesn't work. any ideas?
Dim NewFile As String
Dim ACAD As Object
Dim MyPath As String
On Error Resume Next
Set ACAD = GetObject(, "ACAD.Application")
If Err <> 0 Then
Err.Clear
Set ACAD = CreateObject("autocad.Application")
If Err <> 0 Then
MsgBox "Could Not Load AutoCAD!", vbExclamation
End
End If
End If
On Error GoTo ErrorMessage
' Section 2. Get Excel ready to make the data available.
''MyPath = "C:\Documents and Settings\HP_Administrator\Desktop\SampleSpreadsheet.xls"
''MyPath = "G:\Jerico stuff\marketing\Form Letter\Local Designers.xls"
MyPath = "G:\Programming\Ares PDQ\A0631621.dwg"
NewFile = ACAD.Application.GetOpenFilename("Drawing File (*.dwg), *.dwg", , "Select Drawing File", , False)
MsgBox NewFile
'Set ExcelSheet = Excel.workbooks.Open(NewFile)
GoTo PastErrorMessage
ErrorMessage:
If NewFile = "False" Then End
MsgBox "Could not find the required spreadsheet that should be located at" & vbCr & MyPath & vbCr & "Please rename or relocate the specified file as needed."
End
PastErrorMessage:
Dim NewFile As String
Dim ACAD As Object
Dim MyPath As String
On Error Resume Next
Set ACAD = GetObject(, "ACAD.Application")
If Err <> 0 Then
Err.Clear
Set ACAD = CreateObject("autocad.Application")
If Err <> 0 Then
MsgBox "Could Not Load AutoCAD!", vbExclamation
End
End If
End If
On Error GoTo ErrorMessage
' Section 2. Get Excel ready to make the data available.
''MyPath = "C:\Documents and Settings\HP_Administrator\Desktop\SampleSpreadsheet.xls"
''MyPath = "G:\Jerico stuff\marketing\Form Letter\Local Designers.xls"
MyPath = "G:\Programming\Ares PDQ\A0631621.dwg"
NewFile = ACAD.Application.GetOpenFilename("Drawing File (*.dwg), *.dwg", , "Select Drawing File", , False)
MsgBox NewFile
'Set ExcelSheet = Excel.workbooks.Open(NewFile)
GoTo PastErrorMessage
ErrorMessage:
If NewFile = "False" Then End
MsgBox "Could not find the required spreadsheet that should be located at" & vbCr & MyPath & vbCr & "Please rename or relocate the specified file as needed."
End
PastErrorMessage:





RE: How do I open an AutoCAD file from Excel?
CODE
Dim ACAD As Object
Dim NewFile As Object
Dim MyAcadPath As String
Dim bReadOnly As Boolean
On Error Resume Next
Set ACAD = GetObject(, "ACAD.Application")
If (Err <> 0) Then
Err.Clear
Set ACAD = CreateObject("autocad.Application")
If (Err <> 0) Then
MsgBox "Could Not Load AutoCAD!", vbExclamation
End
End If
End If
'If you want to see AutoCAD on screen
'ACAD.Visible = True
MyAcadPath = "c:\Temp\Drawing2.dwg"
bReadOnly = True
Set 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
Set ACAD = Nothing
Set NewFile = Nothing
End Sub
Also...
Dim ACAD As Object
-->Will work fine. But a better choice would be:
Dim ACAD As AcadApplication
But you first need to go to Tools/References and add
the 'AutoCAD #### Type Library' for this to work.
Just my $0.02
Enjoy
RE: How do I open an AutoCAD file from Excel?