I'm beginer in VBA and I'm trying to write easy program in VBA. But I have a problem with openning DWG file. I have reduced code to basic problem part:
Sub testing()
Dim aplikace As AcadApplication
Set aplikace = ThisDrawing.Application
aplikace.Documents.Open "c:\temp\sablona_list1.dwg", True
Set prostor = ThisDrawing.ModelSpace
End Sub
If it run first time, it will end by automation error. But if I press "Debug" and "F5" it will run to end. Do you know where can be mistake?
I suspect something is wrong with your entire VBA project.
With taht simple code, it should work.
Which version of AutoCAD are you using?
Are you sure the drawing the code is to open a good one?
Could you create and save a new bland drawing; then start a new VBA project and add following simplest code in a VBA module (absolutely nothing else):
Public Sub Test() Dim app As AcadApplication Set app = ThisDrawing.Application app.Documents.Open "C:\temp\Drawingtest1.dwg" Dim model As AcadModelSpace Set model = ThisDrawing.ModelSpace End Sub
and run it.
I have Acad2012/14/15, and of course this simple code works as it should.
If this works for you, then sonething may have made your VBA project "dirty" and you have to find out.
If this simple thing also cause the same error, then I really do not know what it is. You may want to try to repair/reinstall AutoCAD and/or AutoCAD VBA.
Norman Yuan