+ Reply to Thread
Results 1 to 6 of 6

Excel Macro Launch AutoCAD on Completion

Hybrid View

  1. #1
    Registered User
    Join Date
    01-12-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, 2003
    Posts
    84

    Excel Macro Launch AutoCAD on Completion

    I realize this may be a long shot but would it be possible to have an Excel VB Macro do it's thing and then upon completion launch another Windows application like AutoCAD? Like to old days of DOS .bat files.

    I guess I should add here that we'd like the AutoCAD program to open with a specific drawing file already loaded. Kind of like if we used Windows Explorer and clicked on the specific drawing file instead of launching AutoCAD first. We all know this method of clicking on one of the files created by an application will launch that application with that file open and ready for editing.
    Last edited by Vladamir; 01-18-2012 at 09:21 AM.

  2. #2
    Forum Contributor mccrimmon's Avatar
    Join Date
    02-19-2004
    Location
    Scotland
    MS-Off Ver
    2003
    Posts
    249

    Re: Excel Macro Launch AutoCAD on Completion

    You will need to add a reference to the AutoCad librarby within the Reference Library.

    Alt & F11 --> Tools --> References
    Add the AutoCad Reference from the list


    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
    
        strDrawing = "c:\Test.dwg"
        Graphics.Documents.Open (strDrawing)
        
        On Error GoTo 0
    
    End Sub
    McCrimmon

  3. #3
    Registered User
    Join Date
    01-12-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, 2003
    Posts
    84

    Re: Excel Macro Launch AutoCAD on Completion

    Thanks for your reply. I think I follow this but let me ask this question first.

    I have found a way to run AutoCAD from the macro using the SHELL command. But I'm not really comfortable with this. If I recall correctly, using SHELL from a BASIC program does not give up control from the BASIC code until the other application is completed and closed. I'm afraid of users doing something like shutting down Excel before control returns to the macro. Is this a valid concern with today's environment or am I stuck back in the 1980's with my BASIC skills.

    OK - So in the Excel program under Tools > References I chose AutoCAD 2010 Type Library and only that one. There are three other AutoCAD references listed in this menu:

    AutoCAD Focus Control for VBA Type Library
    AutoCAD Map MPolygon Type Library
    AutoCADObjectDBX Common 18.0 Type Library

    I have left those items unchecked. But would there be a need for any others?

    When AutoCAD loads I not only want this particular drawing file to open but some other command line switches can be included (similar to using the SHELL method above) which start certain things happening within AutoCAD as well. I'm wondering if I change the line:

    strDrawing = "c:\Test.dwg"
    to be like this:

    strDrawing = "c:\Test.dwg /b startup"
    will Windows understand this as if I had done the AutoCAD command from the command line including the actutal ACAD.exe file itself. I'm testing some more with this now but any advice would be appreciated. And thank you again.
    Last edited by Vladamir; 01-13-2012 at 09:38 AM.
    Wish I didn't know now what I didn't know then.

  4. #4
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Excel Macro Launch AutoCAD on Completion

    The Shell method is asynchronous, so the code will carry on running to completion while the AutoCAD program is loading.
    Good luck.

  5. #5
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Excel Macro Launch AutoCAD on Completion

    I don't have access to AutoCAD at the moment
    See if this link helps
    http://www.vbaexpress.com/forum/show...thin excel VBA

    Make sure that you have in Excel VBa Tools > References .... "AutoCAD 2005 Type Library" checked/loaded, select your version of AutoCAD.
    If not everything you try will fail.

    [EDIT]
    Ooops where did all these replies come from!!!
    Last edited by Marcol; 01-13-2012 at 09:54 AM.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  6. #6
    Registered User
    Join Date
    01-12-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, 2003
    Posts
    84

    Excel Macro Launch AutoCAD on Completion

    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.
    Last edited by Vladamir; 01-18-2012 at 09:22 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1