I get an error trying to call AutoCAD 2011 from Visual Basic

I get an error trying to call AutoCAD 2011 from Visual Basic

Anonymous
Not applicable
684 Views
5 Replies
Message 1 of 6

I get an error trying to call AutoCAD 2011 from Visual Basic

Anonymous
Not applicable

I get an error trying to call AutoCAD 2011 from Visual Basic. I am not an expert in programming so im trying to find out how to call AutoCAD 2011 from VB.

 

Private Sub Next_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Next.Click

Dim ACAD As Autodesk.AutoCAD.Interop.AcadApplication

ACAD = CreateObject("autocad.Application.18")

ACAD.ActiveDocument.SaveAs("new")

ACAD.ActiveDocument.Save()

ACAD.ActiveDocument.Close()

end sub

 

but everytime i get to the third line, i get an activeX error.

i am really stuck here because i've tryied everything i know and everything i've found on the internet.

thank you

0 Likes
685 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable

I haven't written any VBA code in ACAD since version 2006, but if you can give me some more info, I will try to help.

A couple of questions:

 

What exactly is the end purpose of the sub you are trying to create?

Are you writing the VBA code to reside within an AutoCAD file using the VBA editor in AutoCAD, with VBA in another application, such as Excel, or as a standalone ap created in VB Studio?

0 Likes
Message 3 of 6

pendean
Community Legend
Community Legend
0 Likes
Message 4 of 6

Anonymous
Not applicable

I believe you need to "Set" an object to instanciate it.

 

Set ACAD = CreateObject("autocad.Application.18")

0 Likes
Message 5 of 6

Mike.Wohletz
Collaborator
Collaborator

try changing this line: 

ACAD = CreateObject("autocad.Application.18")

to this:

ACAD = CreateObject("autocad.Application.18.1")

AutoCAD 2011 is version 18.1 and while the first will work if the machine has never had another version of AutoCAD installed. If it has had another version installed it will fail because now you must grab the correct version.

0 Likes
Message 6 of 6

Anonymous
Not applicable

Yes. I also have the same problem. I had cheanged

      ACAD = CreateObject("autocad.Application.18")

to

      ACAD = CreateObject("autocad.Application.18.1")

But it still can not work when the first run. At the second time, it mybe sometime OK and sometime failed

0 Likes