Author Topic: Problem with EXCEL  (Read 1134 times)

0 Members and 1 Guest are viewing this topic.

Jeremy2

  • Mosquito
  • Posts: 12
Problem with EXCEL
« on: June 03, 2022, 12:50:33 PM »
I am having a problem invoking EXCEL. I use this example in the help file:

(vlax-get-or-create-object "Excel.Application")

When I invoke this it displays nothing and freezes AutoCAD to the point I have to use Task  Manager and close
the application. I'm using R13 AutoCAD. What's the problem?

kirby

  • Newt
  • Posts: 132
Re: Problem with EXCEL
« Reply #1 on: June 03, 2022, 02:11:22 PM »
Please confirm
R13 (circa 1995)
or 2013 (circa 2012/13)

If R13, then out of luck for any vl commands and modern windowsy stuff

Jeremy2

  • Mosquito
  • Posts: 12
Re: Problem with EXCEL
« Reply #2 on: June 03, 2022, 03:46:29 PM »
ACADVER variable is 19.0s. Are there any other options?

BIGAL

  • Swamp Rat
  • Posts: 1418
  • 40 + years of using Autocad
Re: Problem with EXCEL
« Reply #3 on: June 03, 2022, 11:23:33 PM »
         ((vl-string-search "R17.2" vrsn) (setq appstr "6.0")) ;2009
         ((vl-string-search "R18.0" vrsn) (setq appstr "7.0")) ;2010
         ((vl-string-search "R18.1" vrsn) (setq appstr "8.0")) ;2011
         ((vl-string-search "R18.2" vrsn) (setq appstr "9.0")) ;2012
         ((vl-string-search "R19.0" vrsn) (setq appstr "10.0")) ;2013
         ((vl-string-search "R19.1" vrsn)(setq appstr "10.3"));;2014
         ((vl-string-search "R20.0" vrsn)(setq appstr "10.4"));;2015
         ((vl-string-search "R20.1" vrsn)(setq appstr "10.5"));;2016     
         ((vl-string-search "R21.0" vrsn)(setq appstr "11.0"));;2017 
         ((vl-string-search "R22.0" vrsn)(setq appstr "12.0"));;2018   
         ((vl-string-search "R23.0" vrsn)(setq appstr "13.0"));;2019
         ((vl-string-search "R23.1" vrsn)(setq appstr "13.2"));;2020
A man who never made a mistake never made anything

kirby

  • Newt
  • Posts: 132
Re: Problem with EXCEL
« Reply #4 on: June 06, 2022, 10:18:40 AM »
See attached, using library routines from Fixo's Excel library.

Fixo uses another technique to find the Excel version, by reading Windows registry.

Code - Auto/Visual Lisp: [Select]
  1. (defun C:TestXLOpen ()
  2. ; Test opening a workbook and selecting a range (Old version)
  3. ; KJM - May 2016
  4. ; Uses custom functions:
  5. ;       xlgetapp (Fixo's library)
  6. ;       xladdbook (Fixo's library)
  7. ;       xlgetreferenceDefrange (Fixo's library mod KJM)
  8.  
  9.  
  10. ; Create a new workbook
  11. (setq ExcelObj (xlgetapp))                      ; Get Excel object
  12. (prompt "\n  Excel object = ")(princ ExcelObj)(princ)
  13.  
  14. (setq MyWorkbook (xladdbook ExcelObj))          ; add a new workbook
  15. (prompt "\n  Workbook object = ")(princ MyWorkbook)(princ)
  16.  
  17.  
  18. (vla-put-visible ExcelObj :vlax-true)
  19.  
  20. ; Pick a cell (this allows user to select from any open workbook)
  21. (setq DefRange "B4")
  22. (setq TargetRangeInfo (xlgetreferenceDefrange ExcelObj "Select cell to receive data in Excel..." "Select Range" DefRange))
  23. (setq TargetRangeObject (nth 0 TargetRangeInfo))
  24. (setq TargetRangeAddress (nth 1 TargetRangeInfo))      
  25.  
  26. (setq MyRow (vlax-get-property TargetRangeObject 'Row))
  27. (setq MyCol (vlax-get-property TargetRangeObject 'Column))
  28. (setq MySheetName  (vlax-get-property  (vlax-get-property TargetRangeObject 'Parent) 'Name))
  29.  
  30. (prompt "\n  Sheet Name = ")(princ MySheetName)(prompt "  Row = ")(princ MyRow)(prompt "  Col = ")(princ MyCol)(princ)
  31.  
  32. ; Clean up
  33. (vlax-release-object TargetRangeObject)
  34. (vlax-release-object MyWorkbook)
  35. )
  36.  
  37.  

Uses Fixo's Excel library (by Oleg Fateev circa 2013), plus some functions that I've extended for my own use. 

Original source of library is here:  https://www.theswamp.org/index.php?topic=38450.0

I've taken the liberty of reformatting and rearranging the library to aid my own comprehension (Fixo hasn't participated for a few years).

Note that some of the functions that try to detect if excel is running have mixed results, sometimes work and sometimes don't work.

BIGAL

  • Swamp Rat
  • Posts: 1418
  • 40 + years of using Autocad
Re: Problem with EXCEL
« Reply #5 on: June 07, 2022, 01:37:19 AM »
(Fixo hasn't participated for a few years).

I have used a few of his routines they were very helpful,  but it is my understanding he has passed away.

Code: [Select]
(or (setq myxl (vlax-get-object "Excel.Application"))
    (setq myxl (vlax-get-or-create-object "excel.Application"))
)
A man who never made a mistake never made anything

mhupp

  • Bull Frog
  • Posts: 250
Re: Problem with EXCEL
« Reply #6 on: June 13, 2022, 08:05:02 AM »
ACADVER variable is 19.0s. Are there any other options?

Make sure there isn't another instance hung up in the background. have a lisp that if things are done out of order it essentially bricks that instance of excel. And opening another instance manually its very sluggish like anywhere from 30 sec to a min. Or trying to run the lisp again links back to the bad excel and doesn't respond. things aren't fixed until I end task on the instance of excel that is hung up.
« Last Edit: June 13, 2022, 08:14:11 AM by mhupp »