+ Reply to Thread
Results 1 to 15 of 15

Run code with AcadOle object

  1. #1
    Registered User
    Join Date
    03-01-2010
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    57

    Run code with AcadOle object

    Hi everyone,

    I got help from cadtutor.net where someone posted the code for a short program that is useful to me. One part, however does not work but it apparently works on their computers. I think it has something to do with References.

    Please Login or Register  to view this content.
    When I run it, I get a User-defined type not defined and the AcadOle line is selected and the Public Sub ExportDims() is highlighted in yellow.

    I have added the following references with no success:

    Microsoft DAO 3.6 Object Library
    Microsoft OLE DB Error Libarary
    oleprn 1.0 Type Library
    Microsoft ActiveX Data Objects 2.7 Library
    OLE Automation

    This is the full code if anyone needs the big picture.
    Please Login or Register  to view this content.
    Last edited by EK1; 04-27-2010 at 11:35 AM. Reason: Change in title

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Run code with AcadOle object

    You need the library for whatever CAD system you're trying to automate -- AutoCAD?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    03-01-2010
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: Run code with AcadOle object

    Ya it's AutoCad 2002 and I'm running it within Autocad but I'm not sure what library to add. I've added those listed in my original post but they don't seem to be enough. I think I'm missing a library that I may have to download or something. Googling has lead me nowhere unfortunately.

  4. #4
    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: Need help to run code with AcadOle object

    Unfortunatly working away from home at the moment.and have limited internet access.

    I have copied your post and code and will have a look.

    Cant test 2002 but will test in AutoCAD 2000 and check in 2003 and 2005

    Look back 29/04/10 and I will try to post for then.

    Cheers

  5. #5
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Need help to run code with AcadOle object

    If you are running it within AutoCAD then I would not expect you to need a reference set for that, since it looks to be a native AutoCAD type. It may just be that it requires a later version than you have.
    PS Per that code, you will also need to set a reference to Excel!
    Remember what the dormouse said
    Feed your head

  6. #6
    Registered User
    Join Date
    03-01-2010
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: Need help to run code with AcadOle object

    Thank you Marcol and romperstomper. You both might be right, it may have to do with my version of Autocad (2002) not being capable enough to run this code.

    Marcol's test should clarify that problem.

    Also, romperstomper, yes it does use an excel file so what reference library do I have to add to set a reference to Excel. Or do I need to add a few lines of code for that?

    Thanks again.

  7. #7
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Need help to run code with AcadOle object

    Do you not have Excel listed under Tools-References in your VBEditor (I don't know AutoCAD at all, so I'm assuming the environment is the same!)

  8. #8
    Registered User
    Join Date
    03-01-2010
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: Need help to run code with AcadOle object

    Ok, I added excel and the code works somewhat. The dialog box opens up as the code says to let me pick a file to which some autocad dimensions will be exported to. But then, the excel file is supposed to open up and the data is to be transferred but nothing happens. The program ends after I pick the file.

    Does it need a reference in the code for excel?

    The VBA editor in AutoCAD is the same as Excel btw and the Tools>References, etc. are all identical to that of the VBA menus in Excel

  9. #9
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Need help to run code with AcadOle object

    Unless you already have Excel open, the application is opened invisibly and the workbook is opened and populated. Have you checked the workbook?

  10. #10
    Registered User
    Join Date
    03-01-2010
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: Need help to run code with AcadOle object

    Looked in the file. Nothing. No update.

    It's weird because I copied and pasted A1:C5 from Sample1.xls (attached) and put it into Autocad as a Reference object. Autocad in turn took it but when I double click on the table within Autocad, it opens up a temporary excel file that is not Sample1.xls but rather C:Documents and Settings user-name Desktop Sample.xls (this file cannot be seen, it's not even hidden, it's just not available anywhere). It only appears when you double click on the little table within autocad.

    My autocad file has a little blurb about what I need happening if possible so it might help eliminate some confusions.

    Please view the attached files. I have attached the sample.dwg as a pdf so you cannot see what I mean about the temporary excel file.
    Attached Files Attached Files

  11. #11
    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: Need help to run code with AcadOle object

    I can't check 2002 but a similar error appears with 2000. I think the next significant version after 2000 was 2003.so it is fair to assume that 2000 does not support AcadOle objects.

    The code runs with a little tweeking and weeding in 2003, 2005 and 2008.

    Does 2002 have
    1/. Tools > Data Links > Data Link Manager....
    2/. Draw > Table....

    Possibly not, but this makes for an easy solution in versions that do.

    I think the solution is to revert to DBconnect, I have limited access at present to the internet so lookback 30-31/04/2010 when I hope to have a solution for you, I'm a bit rusty on the 2000 stuff.so bear with me, It was 10 years ago after all !!!

    Cheers
    Alistair

  12. #12
    Registered User
    Join Date
    03-01-2010
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: Need help to run code with AcadOle object

    Alistair,

    I don't see a Tools>Data in the VB editor or in Autocad. I doubt it exists in 2002. A quick google search revealed that it was introduced first in 2005.

    I will wait for your reply I guess because I'm out of ideas at the moment.

    Thanks for your efforts.

  13. #13
    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: Need help to run code with AcadOle object

    Aye, that's what I thought, but wasn't to sure.

    I'll try it the old fashioned way, DB connect.

    Got to sign off shortly look back tomorrow or the day after

    Alistair

  14. #14
    Registered User
    Join Date
    03-01-2010
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: Need help to run code with AcadOle object

    Ok. I will do some research on DB connect in the meantime because I've only ever heard about it. Never even seen someone using it.

  15. #15
    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: Run code with AcadOle object

    Okay change of plan,

    DB connect is to heavy, because it reads of the jet database the solution is more complicated than it is worth

    Try this.

    1/. With your Excel worksheet create a named range that represents your table.
    Format the columns etc.

    2/. With AutoCAD

    Insert > Ole Object > Microsoft Excel Worksheet > Create from file > Select file > check automatic update.(could be Microsoft Excel 2003 or some thing like that in 2002).

    3/. With AutoCAD, Insert this code in a new module, (careful it goes with ThisDrawing, not Project Global.)
    Please Login or Register  to view this content.

    Change the constants to suit your file names.

    This will not allow you to procede until the two dims have been selected, the solution you had fails if a wrong entity is selected.

    The embeded table does not update in AutoCad until the DWG is saved, closed and reopened. This is standard on these earlier editions.

    This is why I have forced a manual link update.
    I just cannot remember how to finish this off, but try it as it is and I'll dig a bit deeper into my old files for the final solution.
    Might even have to call on AutoLisp for the first time in umpteen years!!!!

    Caution if you double click on the embedded table before it is updated it will overwrite your changes in excel. It's not the friendliest of tools to use.

    I Have run this in both 2000 and 2005 so it should be okay in 2002, let me know of any bugs you find.

    Hope this helps, at least temporarily.

    Alistair
    Last edited by Marcol; 04-30-2010 at 11:31 AM. Reason: Further Clarification

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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