EXCEL 2010 VBA AUTOCAD

EXCEL 2010 VBA AUTOCAD

Anonymous
Not applicable
3,407 Views
5 Replies
Message 1 of 6

EXCEL 2010 VBA AUTOCAD

Anonymous
Not applicable

Hello,

I am in Excel 2010 VBA editor.
I am trying the simple code below (Autocad IS running, I am just trying to access it in order to build some objects)

 

Public Sub GETACAD()
Dim acadApp As AcadApplication
Set acadApp = GetObject(, "AutoCAD.Application")
End Sub

 

It gives me the following error message:
user-defined type not defined.
Any problems with the new EXCEL 2010?

What am I missing?
Please advise

Thank you

Tuli

0 Likes
3,408 Views
5 Replies
Replies (5)
Message 2 of 6

Hallex
Advisor
Advisor

Try change on:
Set acadApp = GetObject(, "AutoCAD.Application18.1")

or whatever you have a current acad release

to get it type in the autocad command line

ACADVER  then press Enter

It will be return something like:

ACADVER = "18.0s (LMS Tech)" (read only)

grab just numeric only value from there and

build your string after:

Set acadApp = GetObject(, "AutoCAD.Application18.0") or 18.1 or 18.2 , ETC

 

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 3 of 6

Anonymous
Not applicable

Thnaks

 

I did that and stiill have the same problem.

I should have mentioned that earlier: I get the error on the line

<<Dim acadApp As AcadApplication>>

0 Likes
Message 4 of 6

truss_85
Advocate
Advocate

Try that it is works fine.

 

Public Sub GETACAD()
On Error Resume Next
Dim acadapp As AcadApplication
Set acadapp = GetObject(, "autocad.application")
If Err Then
    Err.Clear
    Set acadapp = CreateObject("autocad.application")
        If Err Then
            MsgBox Err.Description
            Exit Sub
        End If
End If
End Sub

0 Likes
Message 5 of 6

Hallex
Advisor
Advisor

Would not you forget to add references to AutoCAD 2010 Library?

 

Tools->References->AutoCAD 2010 Library

 

and also for your code logic AutoCad must be open before

 

once more

 

Try late binding? declare as Object:

 

Dim acadApp As Object

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 6 of 6

Hallex
Advisor
Advisor

Try another way

Option Explicit

            Public Sub TryOpenAcad()
            Dim acadApp As AutoCAD.AcadApplication '<-- full path
            Dim acadDoc As AutoCAD.AcadDocument '<-- full path
            Dim fileName As String

            fileName = "C:\Test\WorkingDrawing.dwg" '<-- change a drawing name here
            Set acadApp = New AutoCAD.AcadApplication
            acadApp.Visible = True
            AppActivate acadApp.Caption, True
            Set acadDoc = acadApp.Documents.Open(fileName)
            acadDoc.Activate
            acadApp.WindowState = acMax
            acadApp.Eval "msgbox(""Welcome to AutoCAD window"")"
            acadDoc.Close False, fileName '<-- close without saving
            acadApp.Quit
  
            Set acadDoc = Nothing
            Set acadApp = Nothing
            End Sub

 

Tested on Excel 2007 / Acad 2009 though

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes