I entered the code above from mccrimmon into my macro and assigned a button to it. I think I understand it but the problem with it was that it appeared to open AutoCAD and it may even have opened the drawing I put in
strDrawing = "c:\Test.dwg"
I never saw the AutoCAD window but I did see the icon for it on the taskbar. Then just as quickly it seemed to close down. Then it got strange. Part of the AutoCAD toolbar, the layer properties section to be exact, remained on the screen on top of everything else. AutoCAD was otherwise hell and gone, the icon disappeared from the task bar.
So I ran it again and this time AutoCAD had two icons on the task bar and the drawing I called out was opened, twice. So I closed down one of them and both instances of AutoCAD closed down. I closed everything out and ran it again. The same thing happened. ACAD appeared for a brief moment but only as an Icon on the task bar. I then checked task manager and while the Applications did not show ACAD running the processes showed acad.exe was running and taking up a huge chunk of memory. But there was not sign of AutoCAD on the monitor screens.
Can anyone elaborate more on this and what may be going on?
RESOLVED: Too many threads of code from different sources I guess...here is how it finally came together:
Public Graphics As AcadApplication
Public Sub OpnAcad()
Dim strDrawing As String
On Error Resume Next
Set Graphics = GetObject(, "AutoCAD.Application")
If Err.Description > vbNullString Then
Err.Clear
Set Graphics = CreateObject("AutoCAD.Application")
End If
Graphics.Visible = True
strDrawing = "c:\0\Test.dwg"
Graphics.Documents.Open (strDrawing)
On Error GoTo 0
End Sub
The Graphics.Visible = True was the erroneous line which required correction from the above code.
You have to make sure you load the AutoCAD Type Library in your References in Excel. This will open AutoCAD and so far it appears to be doing exactly what we need. Many thanks for the insightful information.
Bookmarks