Author Topic: msxl-get-ActiveSheet NOT AVAILABLE  (Read 1480 times)

0 Members and 1 Guest are viewing this topic.

sysuwzx

  • Mosquito
  • Posts: 18
msxl-get-ActiveSheet NOT AVAILABLE
« on: April 11, 2016, 02:36:25 AM »
      In the vlxls Project, there are some functions using msxl-get-ActiveSheet function. But since the latest version of excel is 2016, and when i debug, it reminds that the msxl-get-ActiveSheet function is not available. Here's the question—How to get the current worksheet,instead of using the function.
     The project official site is http://www.atablex.com/htmls/vlxls-functions.htm. But now it has gone.

sysuwzx

  • Mosquito
  • Posts: 18
Re: msxl-get-ActiveSheet NOT AVAILABLE
« Reply #1 on: April 11, 2016, 05:23:54 AM »
In other words, how can i get the current worksheet in excel in Office 2010/2016?

ahsattarian

  • Newt
  • Posts: 112
Re: msxl-get-ActiveSheet NOT AVAILABLE
« Reply #2 on: January 11, 2024, 06:54:32 AM »
This is what I normally use   :




Code - Auto/Visual Lisp: [Select]
  1. (setq excel (vlax-get-or-create-object "excel.application"))
  2. (vla-put-visible excel :vlax-true)
  3. (setq workbooks (vlax-get-property excel "workbooks"))
  4. (setq activesheet (vlax-get-property excel "activesheet"))
  5.   ((null activesheet)
  6.    (setq workbook (vlax-invoke-method workbooks "add"))
  7.    (setq worksheets (vlax-get-property workbook "sheets"))
  8.    ;;(setq activesheet (vlax-get-property worksheets 'item 1))
  9.    (setq activesheet (vlax-get-property excel "activesheet"))
  10.    (cond ((null activesheet) (setq activesheet (vlax-invoke-method worksheets "add"))))
  11.   )
  12. )
  13. (setq name (vlax-get-property activesheet "name"))
  14. (setq range (vlax-get-property activesheet "usedrange"))
  15. (setq row1 (vlax-get-property range "row"))
  16. (setq col1 (vlax-get-property range "column"))
  17. (setq drow (vlax-get-property (vlax-get-property range "rows") "count"))
  18. (setq dcol (vlax-get-property (vlax-get-property range "columns") "count"))
  19. (setq row2 (+ row1 drow -1))
  20. (setq col2 (+ col1 dcol -1))





kozmos

  • Newt
  • Posts: 114
Re: msxl-get-ActiveSheet NOT AVAILABLE
« Reply #3 on: January 12, 2024, 10:15:14 PM »
      In the vlxls Project, there are some functions using msxl-get-ActiveSheet function. But since the latest version of excel is 2016, and when i debug, it reminds that the msxl-get-ActiveSheet function is not available. Here's the question—How to get the current worksheet,instead of using the function.
     The project official site is http://www.atablex.com/htmls/vlxls-functions.htm. But now it has gone.
Many years ago, I have abandened atablex.com.

If you want to continue using the lagacy codes with msxl-* functions, you will need first to import them into AutoCAD by calling the function:
Code - Auto/Visual Lisp: [Select]
  1. (Defun vlxls-app-Init
  2.        (/ OSVar GGG Olb8 Olb9 Olb10 TLB Out msg msg1 msg2)
  3.   (setq msg  "\n Initializing Microsoft Excel "
  4.         msg1 "\042Initialization Error\042"
  5.         msg2 (strcat
  6.                "\042 WARNING" "\n ======="
  7.                "\n Can NOT detect Excel97/200X/XP in your computer"
  8.                "\n If you already have Excel installed, please email"
  9.                "\n us to get more solution via kozmosovia@hotmail.com\042")
  10.   )
  11.   (if (null msxl-xl24HourClock)
  12.     (progn
  13.       (if (and (setq GGG
  14.                       (vl-registry-read
  15.                         "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Excel.EXE"
  16.                         "Path"
  17.                       )
  18.                )
  19.                (setq GGG (strcase (strcat GGG "Excel.EXE")))
  20.           )
  21.         (progn
  22.           (foreach OSVar (list "SYSTEMROOT"      "WINDIR"
  23.                                "WINBOOTDIR"      "SYSTEMDRIVE"
  24.                                "USERNAME"        "COMPUTERNAME"
  25.                                "HOMEDRIVE"       "HOMEPATH"
  26.                                "PROGRAMFILES"
  27.                               )
  28.             (if (vl-string-search (strcat "%" OSVar "%") GGG)
  29.               (setq GGG (vl-string-subst
  30.                           (strcase (getenv OSVar))
  31.                           (strcat "%" OSVar "%")
  32.                           GGG
  33.                         )
  34.               )
  35.             )
  36.           )
  37.           (setq Olb8  (findfile (vl-string-subst "EXCEL8.OLB" "EXCEL.EXE" GGG)
  38.                       )
  39.                 Olb9  (findfile (vl-string-subst "EXCEL9.OLB" "EXCEL.EXE" GGG)
  40.                       )
  41.                 Olb10 (findfile
  42.                         (vl-string-subst "EXCEL10.OLB" "EXCEL.EXE" GGG)
  43.                       )
  44.           )
  45.           (cond ((= (vl-filename-base (vl-filename-directory GGG))
  46.                     "OFFICE12"
  47.                  )
  48.                  (setq TLB GGG
  49.                        Out "2007"
  50.                  )
  51.                 )
  52.                 ((= (vl-filename-base (vl-filename-directory GGG))
  53.                     "OFFICE11"
  54.                  )
  55.                  (setq TLB GGG
  56.                        Out "2003"
  57.                  )
  58.                 )              
  59.                 ((= (vl-filename-base (vl-filename-directory GGG))
  60.                     "OFFICE10"
  61.                  )
  62.                  (setq TLB GGG
  63.                        Out "XP"
  64.                  )
  65.                 )
  66.                 (Olb9
  67.                  (setq TLB Olb9
  68.                        Out "2000"
  69.                  )
  70.                 )
  71.                 (Olb8
  72.                  (setq TLB Olb8
  73.                        Out "97"
  74.                  )
  75.                 )
  76.                 (t (setq Out "Version Unknown"))
  77.           )
  78.           (if TLB
  79.             (progn
  80.               (princ (strcat MSG Out "..."))
  81.               (vlax-import-type-library
  82.                 :tlb-filename     TLB               :methods-prefix
  83.                 "msxl-"           :properties-prefix
  84.                 "msxl-"           :constants-prefix "msxl-"
  85.                )
  86.             )
  87.           )
  88.         )
  89.         (progn
  90.           (vldcl-msgbox "x" msg1 msg2)
  91.           (exit)
  92.         )
  93.       )
  94.     )
  95.   )
  96.   msxl-xl24HourClock
  97. )
  98.  

This is lagacy code which worked with very old Excel versions such as Excel XP, for new Excel version, the TLB file is the Excel.EXE. You can simply allocate the path of Excel.EXE and call (vlax-import-type-library
      :tlb-filename     EXCEL.EXEFilePath          :methods-prefix
      "msxl-"        :properties-prefix
      "msxl-"        :constants-prefix "msxl-"
          ) to have the msxl functions imported.

However, this import will bring nearly thousand msxl- functions into AutoCAD but you may only need few of them. As an alternative, you can simply use vlax-get-property and vlax-invoke to only call the Excel methods and properties you need, just as ahsattarian's codes.

(msxl-get-activesheet vlobj) equals to (vlax-get-property vlobj "activeSheet")
« Last Edit: January 12, 2024, 11:24:48 PM by kozmos »
KozMos Inc.

BIGAL

  • Swamp Rat
  • Posts: 1417
  • 40 + years of using Autocad
Re: msxl-get-ActiveSheet NOT AVAILABLE
« Reply #4 on: January 13, 2024, 05:24:29 PM »
I put this together it started life as getexcel.lsp but I didn't like some of the methods used so made some new ones. Acknowledge various people for their help Lee-mac, Gile and Fixo who had extensive Excel functions.

There are other functions out there just takes a bit of Googling to find.
A man who never made a mistake never made anything