Results 1 to 7 of 7

Thread: Link Visual Basic to AutoCAD

  1. #1
    Member
    Join Date
    2005-08
    Posts
    6
    Login to Give a bone
    0

    Default Link Visual Basic to AutoCAD

    Can anybody tell me if it's possible to link visual basic from excel, to AutoCAD? How can I do that?

    thanks

    Bart

  2. #2
    The Silent Type Mike.Perry's Avatar
    Join Date
    2000-11
    Posts
    13,656
    Login to Give a bone
    0

    Default Re: Link Visual Basic to AutoCAD

    Hi Bart

    Please note I have *moved* this thread from the Software forum to this one as I believe it would be better served here.

    Thanks, Mike

    Forum Moderator

  3. #3
    The Silent Type Mike.Perry's Avatar
    Join Date
    2000-11
    Posts
    13,656
    Login to Give a bone
    0

    Default Re: Link Visual Basic to AutoCAD

    Hi

    For starters take a look at the following threads and all! the links found within...

    dbconnect

    Using VBA to pull values from Excel and into attributes

    Automatic BOM Generation

    DATABASE

    Have a good one, Mike
    Last edited by Mike.Perry; 2006-04-01 at 01:11 AM. Reason: Correct formatting

  4. #4
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,420
    Login to Give a bone
    0

    Default Re: Link Visual Basic to AutoCAD

    In case none of those mention it, there's a sample that got installed with acad.
    C:> ED WORKING....


    LinkedIn

  5. #5
    I could stop if I wanted to
    Join Date
    2003-03
    Location
    Alberta
    Posts
    260
    Login to Give a bone
    0

    Default Re: Link Visual Basic to AutoCAD

    Yes, yes you can. Which way to you want to communicate, AutoCAD controls Excel or Excel controls AutoCAD? And do you want data to come from an existing file or create a new one?


    Here's a quicky example of creating a new instance of Excel from AutoCAD and then closing it down.

    Sub ABC()
    Dim oExcel As Object

    Set oExcel = CreateObject("Excel.Application")
    ' Insert desired code here.
    oExcel.Quit
    End Sub

  6. #6
    100 Club mtuersley's Avatar
    Join Date
    2001-12
    Posts
    122
    Login to Give a bone
    0

    Default Re: Link Visual Basic to AutoCAD

    While it'll work, I wouldn't do it that way. That's the first mistake people make is referencing and using Excel itself. Talk about resource and time consuming! Also, what if the user doesn't have Excel? That sounds odd in today's work place but I run across it often enough.

    The better approach is to use ADO. Most people don't realize that you can use ADO to talk to anything from Access to a simple ASCII text file without having the authoring program installed. Here's a quickie function for accomplishing it this way. Its simple, straight forward, and FAST.

    Private Function Read_Excel(ByVal sFile As String) As Recordset
    '+--Read Excel File Using ADO
    Dim oConn As ADODB.Connection
    Set oConn = New ADODB.Connection
    oConn = "DRIVER=Microsoft Excel Driver (*.xls);" & "DBQ="
    Dim oRS As Recordset
    Set oRS = New Recordset
    On Error GoTo Exit_Here
    With oRS
    .CursorLocation = adUseClient
    .CursorType = adOpenKeyset
    .LockType = adLockBatchOptimistic
    .Open "SELECT * FROM [sheet1$]", oConn & sFile
    End With
    'set return value
    Set Read_Excel = oRS
    Set oRS = Nothing

    Exit_Here:

    End Function
    There are other options for pulling the data besides the brute force grab all approach - just look up in a JET help file. Also, with this approach, you need to append any cell you read with a blanket & "" just in case there is no value in the cell. Otherwise, it'll pop a null error message on you. Or, you can move the recordset to either a collection or a dictionary and they will handle the null value for you.

  7. #7
    Member
    Join Date
    2005-08
    Posts
    6
    Login to Give a bone
    0

    Default Re: Link Visual Basic to AutoCAD

    Quote Originally Posted by bweir
    Yes, yes you can. Which way to you want to communicate, AutoCAD controls Excel or Excel controls AutoCAD? And do you want data to come from an existing file or create a new one?


    Here's a quicky example of creating a new instance of Excel from AutoCAD and then closing it down.

    Sub ABC()
    Dim oExcel As Object

    Set oExcel = CreateObject("Excel.Application")
    ' Insert desired code here.
    oExcel.Quit
    End Sub
    We want AutoCAD to control Excel. What we mean is: if we draw a rectangle in AutoCAD and we give it dimensions for example length 100, width 50. With a simple action we want those 2 dimensions to appear in excel.

    Thanks Bart

Similar Threads

  1. AutoCAD 2012 slow with Visual Basic 6.0
    By jfrias751497 in forum VBA/COM Interop
    Replies: 5
    Last Post: 2011-06-03, 02:09 PM
  2. Autocad LT vs Visual Basic 6
    By hibbe.wiersma172517 in forum ARX
    Replies: 2
    Last Post: 2008-08-21, 08:16 AM
  3. The future of Visual Basic
    By MikeJarosz in forum VBA/COM Interop
    Replies: 4
    Last Post: 2006-08-04, 06:29 PM
  4. Microsoft Visual Basic
    By jcronburg in forum VBA/COM Interop
    Replies: 1
    Last Post: 2004-06-16, 07:49 PM

Posting Permissions

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