Jump to content

CAD output excel specified page


ekko

Recommended Posts

(setq xlApp    (vlax-get-or-create-object "Excel.Application")
      xlBooks  (vlax-get-property xlApp "Workbooks")
      ;xlBook   (vlax-invoke-method xlBooks "Add");Get the active excel that is currently open, instead of adding a new one
      xlSheets (vlax-get-property xlBook "Sheets")
      xlSheet  (vlax-get-property xlSheets "Item" 2)
      xlCells  (vlax-get-property xlSheet "Cells")
)

May I ask how to get the sheet2 page in the currently opened table, how to modify the above code, can it be achieved?

202203271.png

Link to comment
Share on other sites

Something like this with your variable names

 

getexecel.lsp:        (vlax-put-property (vlax-invoke-method (vlax-get-property *ExcelApp% "Sheets") "Add") "Name" SheetName$)

Link to comment
Share on other sites

3 hours ago, BIGAL said:

Something like this with your variable names

 

getexecel.lsp:        (vlax-put-property (vlax-invoke-method (vlax-get-property *ExcelApp% "Sheets") "Add") "Name" SheetName$)

It doesn't seem to work, or I'm using it wrong, can you elaborate? thanks

Link to comment
Share on other sites

11 hours ago, ekko said:
(setq xlApp    (vlax-get-or-create-object "Excel.Application")
      xlBooks  (vlax-get-property xlApp "Workbooks")
      ;xlBook   (vlax-invoke-method xlBooks "Add");Get the active excel that is currently open, instead of adding a new one
      xlSheets (vlax-get-property xlBook "Sheets")
      xlSheet  (vlax-get-property xlSheets "Item" 2)
      xlCells  (vlax-get-property xlSheet "Cells")
)

May I ask how to get the sheet2 page in the currently opened table, how to modify the above code, can it be achieved?

202203271.png

I think maybe my description is not clear enough. My requirement is that the data can be arbitrarily output to any specified page in the Excel table, such as sheet1 sheet2 sheet3... pages

Edited by ekko
Link to comment
Share on other sites

; ESCUR, ESADD, ESDEL, ESUHD / ECSEL, ECPUT, ECGET, ECADR - 2022.03.30 exceed
; https://www.cadtutor.net/forum/topic/74681-cad-output-excel-specified-page/#comment-591539

; before you run this lisp - Open both CAD and Excel.
; If multiple Excel windows are open, the top Excel window is selected.
; The order can be changed with Alt+Tab. Place the target Excel window right behind the CAD
; It is NOT executed when a cell value or formula is being edited (in edit mode)
; It is NOT executed when a save prompt is floating, or any other excel dialog box is running.
; please complete all these tasks and run this lisp

; 1. Excel Sheet Control Lisp

; ESCUR - change current excel sheet
; If you enter ESCUR, the sheet name list of the Excel workbook is displayed. 
; when you enter a sheet order number, the active sheet changes to that sheet.
; hidden sheets are included in the list. If you enter a hidden sheet number, 
; you cannot see it before you modify the property, so in this case, another sheet will be selected.

; ESADD - add new excel sheet
; If you enter ESADD, you can select the list of sheets in the current Excel and where to add them. 
; If you press the space bar without entering anything, it will be created at the end. 
; You must enter a sheet name.
; Duplicate name check function is added.

; (ex:esadd "1" "sheetnameyouwant")
; this is sub routine module, for insert ESADD to another lisp
; "1" - means sheet order number. this is string, NOT NUMBER format. it can have "" empty value. this mean add the last sheet.
; "sheetnameyouwnat" - new sheet name. this is string
; example 1
; (ex:esadd "" "MySheet1234")
; this will find MySheet1234 in your Excel Workbook. if it doesn't have that sheet. it will add the last sheet "MySheet1234"
; if it has "MySheet1234", just activate MySheet1234 sheet.
; example 2
; (ex:esadd "3" "MySheet1234")
; find "MySheet1234" and if it doesn't have. add 3rd sheet "MySheet1234", old sheets after 3rd sheet, go to back from 4th sheet.
; if it has "MySheet1234", just activate MySheet1234 sheet.

; ESDEL - delete excel sheet
; Since the Excel workbook has to have at least one sheet, it escapes when there is one left.

; ESUHD - unhide all hided sheets

; 2. Excel Cell Control Lisp

; ECSEL - select active cell command
; visible cursor does not move. but, in Excel, address field in the upper left corner, you can see that the active cell has been changed.
; In practice, you will use it more this way.
; (ex:ecsel r c)
; sub routine version of ECSEL
; r = row, c = column
; activate cell in active sheet.

; ECPUT - put text value in active cell command
; In practice, you will use it more this way.
; (ex:ecput "textstring")
; sub routine version of ECPUT
; can input any text string in active cell. 

; ECGET - get text value in active cell command
; In practice, you will use it more this way.
; (setq aaa (ex:ecget))
; (princ aaa)
; sub routine version of ECGET


(vl-load-com)


(defun c:ESCUR ( / *error* excelapp workbooks sheets acsheet sheetnamelist acsheetname selectsheetname sht shlen index hideunhide captionname selectsheetno )
 (setvar "cmdecho" 0)
    (defun *error* ( msg )
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\n Error: " msg))
        )
        (vlax-release-object AcSheet)
        (vlax-release-object Sheets)
        (vlax-release-object Workbooks)
        (vlax-release-object ExcelApp)
        (setvar "cmdecho" 1)
        (princ)
    ) 
 ;BIGAL's ah:chkexcel
 (if (= (setq excelapp (vlax-get-object "Excel.Application") ) nil) ; if open already
     (setq excelapp (vlax-get-or-create-object "Excel.Application"))    
 )
 (if (= (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet)) nil)
    (vlax-invoke-method (vlax-get-property excelapp 'Workbooks) 'Add)
 )
 (vlax-put Excelapp "visible" :vlax-true)
 (if (/= (setq captionname (vlax-get-property ExcelApp 'caption)) nil)
    (progn
      (princ "\n workbook name - ")
      (princ captionname)
    );end of progn
 )

 (setq Workbooks (vlax-get-property ExcelApp 'Workbooks))
 (setq Sheets (vlax-get-property ExcelApp 'Sheets))
 (setq AcSheet (vlax-get-property ExcelApp 'ActiveSheet))
 (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
 (setq acsheetname (vlax-get-property acsheet 'name))

 (princ "\n active sheet now - ")
 (princ acsheetname)
 ;(princ "\n sheets name list - ")
 ;(princ sheetnamelist)

 (setq shlen (length sheetnamelist))
 (setq index 0)
 (princ "\n [ Number ] - Sheet Name ")
 (repeat shlen
   (setq hideunhide (vlax-get-property (vlax-get-property sheets 'item (nth index sheetnamelist)) 'visible))
   (if (= hideunhide 0)
     (progn 
        (princ "\n [ Hided ] - ") 
        (princ (nth index sheetnamelist))
     )
     (progn 
        (princ "\n [ ")
        (princ (+ index 1))
        (princ " ] - ")
        (princ (nth index sheetnamelist))
     );end of progn
   );end of if
   (setq index (+ index 1))
 )

(initget 7)
(setq selectsheetno (getint "\n input sheet number - "))

 (if (= (vlax-get-property (vlax-get-property sheets 'item (nth (- selectsheetno 1) sheetnamelist)) 'visible) 0)
   (progn 
      (setq selectsheetname (nth (- selectsheetno 1) SheetNameList))
      (princ "\n selected sheet name - ")
      (princ (vl-princ-to-string selectsheetname))
      (princ "\n cannot select to current sheet, it is hided sheet.")
      (setq acsheetname (vlax-get-property acsheet 'name))
      (princ "\n activated sheet name - ")
      (princ acsheetname)
      (exit)
   );end of progn
   (progn 
      (setq selectsheetname (nth (- selectsheetno 1) SheetNameList))
      (princ "\n selected sheet name - ")
      (princ (vl-princ-to-string selectsheetname))
      (setq sht (vlax-get-property sheets 'Item selectsheetname))
      (setq acsheet (vlax-invoke-method sht 'Activate)) 
      (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
      (setq acsheetname (vlax-get-property acsheet 'name))
      (princ "\n your selected sheet is activated - ")
      (princ acsheetname)
    );end of progn
 );end of if
 ;(vlax-dump-object acsheet)  ;if you delete ";" in first of this line. can get dump vl property of activated sheet you selected


 (vlax-release-object AcSheet)
 (vlax-release-object Sheets)
 (vlax-release-object Workbooks)
 (vlax-release-object ExcelApp)
 (setvar "cmdecho" 1)
 (princ)
)

(defun ex:ESCUR ( selectsheetno / *error* excelapp workbooks sheets acsheet sheetnamelist acsheetname selectsheetname sht shlen index hideunhide captionname)
 (setvar "cmdecho" 0)
    (defun *error* ( msg )
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\n Error: " msg))
        )
        (vlax-release-object AcSheet)
        (vlax-release-object Sheets)
        (vlax-release-object Workbooks)
        (vlax-release-object ExcelApp)
        (setvar "cmdecho" 1)
        (princ)
    ) 
 ;BIGAL's ah:chkexcel
 (if (= (setq excelapp (vlax-get-object "Excel.Application") ) nil) ; if open already
     (setq excelapp (vlax-get-or-create-object "Excel.Application"))    
 )
 (if (= (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet)) nil)
    (vlax-invoke-method (vlax-get-property excelapp 'Workbooks) 'Add)
 )
 (vlax-put Excelapp "visible" :vlax-true)
 (if (/= (setq captionname (vlax-get-property ExcelApp 'caption)) nil)
    (progn
      (princ "\n workbook name - ")
      (princ captionname)
    );end of progn
 )

 (setq Workbooks (vlax-get-property ExcelApp 'Workbooks))
 (setq Sheets (vlax-get-property ExcelApp 'Sheets))
 (setq AcSheet (vlax-get-property ExcelApp 'ActiveSheet))
 (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
 (setq acsheetname (vlax-get-property acsheet 'name))

 (princ "\n active sheet now - ")
 (princ acsheetname)
 ;(princ "\n sheets name list - ")
 ;(princ sheetnamelist)

 (setq shlen (length sheetnamelist))
 (setq index 0)
 (princ "\n [ Number ] - Sheet Name ")
 (repeat shlen
   (setq hideunhide (vlax-get-property (vlax-get-property sheets 'item (nth index sheetnamelist)) 'visible))
   (if (= hideunhide 0)
     (progn 
        (princ "\n [ Hided ] - ") 
        (princ (nth index sheetnamelist))
     )
     (progn 
        (princ "\n [ ")
        (princ (+ index 1))
        (princ " ] - ")
        (princ (nth index sheetnamelist))
     );end of progn
   );end of if
   (setq index (+ index 1))
 )



 (if (= (vlax-get-property (vlax-get-property sheets 'item (nth (- selectsheetno 1) sheetnamelist)) 'visible) 0)
   (progn 
      (setq selectsheetname (nth (- selectsheetno 1) SheetNameList))
      (princ "\n selected sheet name - ")
      (princ (vl-princ-to-string selectsheetname))
      (princ "\n cannot select to current sheet, it is hided sheet.")
      (setq acsheetname (vlax-get-property acsheet 'name))
      (princ "\n activated sheet name - ")
      (princ acsheetname)
      (exit)
   );end of progn
   (progn 
      (setq selectsheetname (nth (- selectsheetno 1) SheetNameList))
      (princ "\n selected sheet name - ")
      (princ (vl-princ-to-string selectsheetname))
      (setq sht (vlax-get-property sheets 'Item selectsheetname))
      (setq acsheet (vlax-invoke-method sht 'Activate)) 
      (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
      (setq acsheetname (vlax-get-property acsheet 'name))
      (princ "\n your selected sheet is activated - ")
      (princ acsheetname)
    );end of progn
 );end of if
 ;(vlax-dump-object acsheet)  ;if you delete ";" in first of this line. can get dump vl property of activated sheet you selected


 (vlax-release-object AcSheet)
 (vlax-release-object Sheets)
 (vlax-release-object Workbooks)
 (vlax-release-object ExcelApp)
 (setvar "cmdecho" 1)
 (princ)
)



(defun c:ESUHD ( / *error* excelapp workbooks sheets acsheet sheetnamelist acsheetname selectsheetno selectsheetname sht shlen index hideunhide hidecount unhideanswer captionname)
 (setvar "cmdecho" 0)
    (defun *error* ( msg )
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\n Error: " msg))
        )
        (vlax-release-object AcSheet)
        (vlax-release-object Sheets)
        (vlax-release-object Workbooks)
        (vlax-release-object ExcelApp)
        (setvar "cmdecho" 1)
        (princ)
    ) 
 ;BIGAL's ah:chkexcel
 (if (= (setq excelapp (vlax-get-object "Excel.Application") ) nil) ; if open already
     (setq excelapp (vlax-get-or-create-object "Excel.Application"))    
 )
 (if (= (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet)) nil)
    (vlax-invoke-method (vlax-get-property excelapp 'Workbooks) 'Add)
 )
 (vlax-put Excelapp "visible" :vlax-true)
 (if (/= (setq captionname (vlax-get-property ExcelApp 'caption)) nil)
    (progn
      (princ "\n workbook name - ")
      (princ captionname)
    );end of progn
 )


 (vlax-put Excelapp "visible" :vlax-true)
 (setq Workbooks (vlax-get-property ExcelApp 'Workbooks))
 (setq Sheets (vlax-get-property ExcelApp 'Sheets))
 (setq AcSheet (vlax-get-property ExcelApp 'ActiveSheet))
 (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
 (setq acsheetname (vlax-get-property acsheet 'name))

 (princ "\n active sheet now - ")
 (princ acsheetname)
 ;(princ "\n sheets name list - ")
 ;(princ sheetnamelist)

 (setq shlen (length sheetnamelist))
 (setq index 0)
 (setq hidecount 0)
 (princ "\n [ Number ] - Sheet Name ")
 (repeat shlen
   (setq hideunhide (vlax-get-property (vlax-get-property sheets 'item (nth index sheetnamelist)) 'visible))
   (if (= hideunhide 0)
     (progn 
        (princ "\n [ Hided ] - ") 
        (princ (nth index sheetnamelist))
        (setq hidecount (+ hidecount 1))
     )
     (progn 
        (princ "\n [ ")
        (princ (+ index 1))
        (princ " ] - ")
        (princ (nth index sheetnamelist))
     );end of progn
   );end of if
   (setq index (+ index 1))
 )

 
 (if (/= hidecount 0)
   (progn
     (princ "\n There's ")
     (princ hidecount)
     (princ " sheets hided. ")
     (setq unhideanswer (strcase (getstring "unhide these all sheet? (Y/N) : ")))
     (cond 
       ((= unhideanswer "Y")
        (setq index 0)
        (repeat shlen
          (setq hideunhide (vlax-get-property (vlax-get-property sheets 'item (nth index sheetnamelist)) 'visible))
          (if (= hideunhide 0)
            (progn 
              (vlax-put-property (vlax-get-property sheets 'item (nth index sheetnamelist)) 'visible -1)
              (princ "\n [ ")
              (princ (+ index 1))
              (princ " ] - ")
              (princ (nth index sheetnamelist))
              (princ " - Unhide Complete")
            )
            (progn 
              (princ "\n [ ")
              (princ (+ index 1))
              (princ " ] - ")
              (princ (nth index sheetnamelist))
            );end of progn
          );end of if
          (setq index (+ index 1))
         ); end of repeat
       ); end of cond option 1
       ((/= unhideanswer "Y")
         (exit)); end of cond option 2
     );end of cond
   );end of progn
   (progn
     (princ "\n There's no hided sheets.")
   );end of progn
 );end of if
 ;(vlax-dump-object acsheet)  ;if you delete ";" in first of this line. can get dump vl property of activated sheet you selected

 (vlax-release-object AcSheet)
 (vlax-release-object Sheets)
 (vlax-release-object Workbooks)
 (vlax-release-object ExcelApp)
 (setvar "cmdecho" 1)
 (princ)
)




(defun c:ESADD ( / *error* excelapp workbooks sheets acsheet sheetnamelist acsheetname shlen index selectsheetno selectsheetname sht newsheetname strcasedlist captionname)
 (setvar "cmdecho" 0)
    (defun *error* ( msg )
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\n Error: " msg))
        )
        (vlax-release-object AcSheet)
        (vlax-release-object Sheets)
        (vlax-release-object Workbooks)
        (vlax-release-object ExcelApp)
        (setvar "cmdecho" 1)
        (princ)
    ) 
 ;BIGAL's ah:chkexcel
 (if (= (setq excelapp (vlax-get-object "Excel.Application") ) nil) ; if open already
     (setq excelapp (vlax-get-or-create-object "Excel.Application"))    
 )
 (if (= (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet)) nil)
    (vlax-invoke-method (vlax-get-property excelapp 'Workbooks) 'Add)
 )
 (if (/= (setq captionname (vlax-get-property ExcelApp 'caption)) nil)
    (progn
      (princ "\n workbook name - ")
      (princ captionname)
    );end of progn
 )

 (vlax-put Excelapp "visible" :vlax-true)
 (setq Workbooks (vlax-get-property ExcelApp 'Workbooks))
 (setq Sheets (vlax-get-property ExcelApp 'Sheets))
 (setq AcSheet (vlax-get-property ExcelApp 'ActiveSheet))
 (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
 (setq acsheetname (vlax-get-property acsheet 'name))

 (princ "\n active sheet now - ")
 (princ acsheetname)
 ;(princ "\n sheets name list - ")
 ;(princ sheetnamelist)

 (setq shlen (length sheetnamelist))
 (setq index 0)
 (princ "\n [ Number ] - Sheet Name ")
 (repeat shlen
   (princ "\n [ ")
   (princ (+ index 1))
   (princ " ] - ")
   (princ (nth index sheetnamelist))
   (setq index (+ index 1))
 )

 (setq strcasedlist (mapcar 'strcase sheetnamelist))



 (setq selectsheetno (getstring "\n input order of new sheet (just space bar = add a new sheet at the end) - "))
 (cond 
   ((and (/= selectsheetno "") (< (abs (atoi selectsheetno)) (+ shlen 1)))
     (setq selectsheetno (abs (atoi selectsheetno)))
     (setq selectsheetname (nth (- selectsheetno 1) SheetNameList))
     (setq sht (vlax-get-property sheets 'Item selectsheetname))
     (setq acsheet (vlax-invoke-method sht 'Activate)) 
     (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
     (setq newsheetname (getstring t "\n input new sheet name : "))
     (if (/= newsheetname "")
       (progn 
         (if (= (car (member (strcase newsheetname) strcasedlist)) nil)
           (vlax-put-property (vlax-invoke-method Sheets 'Add) 'Name newsheetname)
           (progn
             (princ "\n cannot make with duplicated name. please retry ")
             (setq sht (vlax-get-property sheets 'Item newsheetname))
             (setq acsheet (vlax-invoke-method sht 'Activate)) 
             (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
             (setq acsheetname (vlax-get-property acsheet 'name))
             (princ "\n your new sheet is activated - ")
             (princ acsheetname)
             (exit)
           )
         );end of if
       );end of progn
     );end of if
     (setq sht (vlax-get-property sheets 'Item newsheetname))
     (setq acsheet (vlax-invoke-method sht 'Activate)) 
     (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
     (setq acsheetname (vlax-get-property acsheet 'name))
     (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
     (setq shlen (length sheetnamelist))
     (setq index 0)
     (princ "\n [ Number ] - Sheet Name ")
     (repeat shlen
       (princ "\n [ ")
       (princ (+ index 1))
       (princ " ] - ")
       (princ (nth index sheetnamelist))
       (setq index (+ index 1))
     )
     (princ "\n")
     (princ "\n your new sheet is activated - ")
     (princ acsheetname)
     (princ "\n")
   );end of cond option 1
   ((and (/= selectsheetno "") (> (abs (atoi selectsheetno)) (+ shlen 1)) ) 
     (princ "\n invalid sheet no. exceed number of sheets")
   );end of cond option 2
   ((or (= selectsheetno "") (= (abs (atoi selectsheetno)) (+ shlen 1)))
     (setq selectsheetno 1)
     (setq selectsheetname (nth (- selectsheetno 1) SheetNameList))
     (setq sht (vlax-get-property sheets 'Item selectsheetname))
     (setq acsheet (vlax-invoke-method sht 'Activate)) 
     (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
     (setq newsheetname (getstring t "\n Adds a sheet to the last position. \n input new sheet name : "))
     (if (/= newsheetname "")
       (progn 
         (if (= (car (member (strcase newsheetname) strcasedlist)) nil)
           (vlax-put-property (vlax-invoke-method Sheets 'Add) 'Name newsheetname)
           (progn
             (princ "\n cannot make with duplicated name. please retry ")
             (setq sht (vlax-get-property sheets 'Item newsheetname))
             (setq acsheet (vlax-invoke-method sht 'Activate)) 
             (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
             (setq acsheetname (vlax-get-property acsheet 'name))
             (princ "\n your new sheet is activated - ")
             (princ acsheetname)
             (exit)
           )
         );end of if
       );end of progn
     );end of if
     (setq sht (vlax-get-property sheets 'Item newsheetname))
     (setq acsheet (vlax-invoke-method sht 'Activate)) 
     (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
     (setq acsheetname (vlax-get-property acsheet 'name))
     (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
     (setq shlen (length sheetnamelist))
     (vlax-invoke-method sht 'move (vlax-get-property sheets "item" shlen))
     (vlax-invoke-method (vlax-get-property sheets 'item shlen) 'move (vlax-get-property sheets "item" (- shlen 1)))
     (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
     (setq index 0)
     (princ "\n [ Number ] - Sheet Name ")
     (repeat shlen
       (princ "\n [ ")
       (princ (+ index 1))
       (princ " ] - ")
       (princ (nth index sheetnamelist))
       (setq index (+ index 1))
     )
     (princ "\n")
     (vlax-invoke-method sht 'Activate)
     (princ "\n your new sheet is activated - ")
     (princ acsheetname)
     (princ "\n")
   );end of cond option 3
);end of cond
 (vlax-release-object AcSheet)
 (vlax-release-object Sheets)
 (vlax-release-object Workbooks)
 (vlax-release-object ExcelApp)
 (setvar "cmdecho" 1)
(princ)
)


(defun c:ESDEL ( / *error* myxl excelapp workbooks sheets acsheet sheetnamelist acsheetname selectsheetno selectsheetname sht shlen index captionname)
 (setvar "cmdecho" 0)
    (defun *error* ( msg )
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\n Error: " msg))
        )
        (vlax-release-object AcSheet)
        (vlax-release-object Sheets)
        (vlax-release-object Workbooks)
        (vlax-release-object ExcelApp)
        (setvar "cmdecho" 1)
        (princ)
    ) 
 ;BIGAL's ah:chkexcel
 (if (= (setq excelapp (vlax-get-object "Excel.Application") ) nil) ; if open already
     (setq excelapp (vlax-get-or-create-object "Excel.Application"))    
 )
 (if (= (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet)) nil)
    (vlax-invoke-method (vlax-get-property excelapp 'Workbooks) 'Add)
 )
 (vlax-put Excelapp "visible" :vlax-true)
 (if (/= (setq captionname (vlax-get-property ExcelApp 'caption)) nil)
    (progn
      (princ "\n workbook name - ")
      (princ captionname)
    );end of progn
 )
 (vlax-put Excelapp "visible" :vlax-true)
 (setq Workbooks (vlax-get-property ExcelApp 'Workbooks))
 (setq Sheets (vlax-get-property ExcelApp 'Sheets))
 (setq AcSheet (vlax-get-property ExcelApp 'ActiveSheet))
 (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
 (setq acsheetname (vlax-get-property acsheet 'name))

 (princ "\n active sheet now - ")
 (princ acsheetname)
 ;(princ "\n sheets name list - ")
 ;(princ sheetnamelist)

 (setq shlen (length sheetnamelist))
 (setq index 0)
 (princ "\n [ Number ] - Sheet Name ")
 (repeat shlen
   (princ "\n [ ")
   (princ (+ index 1))
   (princ " ] - ")
   (princ (nth index sheetnamelist))
   (setq index (+ index 1))
 );end of repeat

 (if (< shlen 2)
   (princ "\n you cannot delete last 1 sheet")
   (progn 

     (initget 7)
     (setq selectsheetno (getint "\n input sheet number you want to delete - "))
     (setq selectsheetname (nth (- selectsheetno 1) SheetNameList))
     (princ "\n selected sheet name to delete - ")
     (princ (vl-princ-to-string selectsheetname))
     (vlax-for item sheets
       (if (= (vlax-get-property item 'Name) selectsheetname)
         (vlax-invoke-method item 'Delete)
       )
     )
     (setq SheetNameList '())
       (vlax-for item Sheets
         (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
       )
     (setq shlen (length sheetnamelist))
     (setq index 0)
     (princ "\n [ Number ] - Sheet Name ")
     (repeat shlen
       (princ "\n [ ")
       (princ (+ index 1))
       (princ " ] - ")
       (princ (nth index sheetnamelist))
       (setq index (+ index 1))
     );end of repeat
   );end of progn
 );end of if
 (vlax-release-object AcSheet)
 (vlax-release-object Sheets)
 (vlax-release-object Workbooks)
 (vlax-release-object ExcelApp)
 (setvar "cmdecho" 1)
 (princ)
)


(defun ex:esadd ( selectsheetno newsheetname / *error* excelapp workbooks sheets acsheet sheetnamelist acsheetname shlen index selectsheetname sht strcasedlist captionname)
 (setvar "cmdecho" 0)
    (defun *error* ( msg )
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\n Error: " msg))
        )
        (vlax-release-object AcSheet)
        (vlax-release-object Sheets)
        (vlax-release-object Workbooks)
        (vlax-release-object ExcelApp)
        (setvar "cmdecho" 1)
        (princ)
    ) 
 ;BIGAL's ah:chkexcel
 (if (= (setq excelapp (vlax-get-object "Excel.Application") ) nil) ; if open already
     (setq excelapp (vlax-get-or-create-object "Excel.Application"))    
 )
 (if (= (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet)) nil)
    (vlax-invoke-method (vlax-get-property excelapp 'Workbooks) 'Add)
 )
 (vlax-put Excelapp "visible" :vlax-true)
 (if (/= (setq captionname (vlax-get-property ExcelApp 'caption)) nil)
    (progn
      (princ "\n workbook name - ")
      (princ captionname)
    );end of progn
 )
 (vlax-put Excelapp "visible" :vlax-true)
 (setq Workbooks (vlax-get-property ExcelApp 'Workbooks))
 (setq Sheets (vlax-get-property ExcelApp 'Sheets))
 (setq AcSheet (vlax-get-property ExcelApp 'ActiveSheet))
 (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
 (setq acsheetname (vlax-get-property acsheet 'name))

 (princ "\n active sheet now - ")
 (princ acsheetname)
 ;(princ "\n sheets name list - ")
 ;(princ sheetnamelist)

 (setq shlen (length sheetnamelist))
 (setq index 0)
 (princ "\n [ Number ] - Sheet Name ")
 (repeat shlen
   (princ "\n [ ")
   (princ (+ index 1))
   (princ " ] - ")
   (princ (nth index sheetnamelist))
   (setq index (+ index 1))
 )

 (setq strcasedlist (mapcar 'strcase sheetnamelist))



 ;(setq selectsheetno (getstring "\n input order of new sheet (just space bar = add a new sheet at the end) - "))
 (cond 
   ((and (/= selectsheetno "") (< (abs (atoi selectsheetno)) (+ shlen 1)))
     (setq selectsheetno (abs (atoi selectsheetno)))
     (setq selectsheetname (nth (- selectsheetno 1) SheetNameList))
     (setq sht (vlax-get-property sheets 'Item selectsheetname))
     (setq acsheet (vlax-invoke-method sht 'Activate)) 
     (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
     ;(setq newsheetname (getstring t "\n input new sheet name : "))
     (if (/= newsheetname "")
       (progn 
         (if (= (car (member (strcase newsheetname) strcasedlist)) nil)
           (vlax-put-property (vlax-invoke-method Sheets 'Add) 'Name newsheetname)
           (progn
             (princ "\n cannot make with duplicated name. please retry ")
             (setq sht (vlax-get-property sheets 'Item newsheetname))
             (setq acsheet (vlax-invoke-method sht 'Activate)) 
             (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
             (setq acsheetname (vlax-get-property acsheet 'name))
             (princ "\n your new sheet is activated - ")
             (princ acsheetname)
             (exit)
           )
         );end of if
       );end of progn
     );end of if
     (setq sht (vlax-get-property sheets 'Item newsheetname))
     (setq acsheet (vlax-invoke-method sht 'Activate)) 
     (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
     (setq acsheetname (vlax-get-property acsheet 'name))
     (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
     (setq shlen (length sheetnamelist))
     (setq index 0)
     (princ "\n [ Number ] - Sheet Name ")
     (repeat shlen
       (princ "\n [ ")
       (princ (+ index 1))
       (princ " ] - ")
       (princ (nth index sheetnamelist))
       (setq index (+ index 1))
     )
     (princ "\n")
     (princ "\n your new sheet is activated - ")
     (princ acsheetname)
     (princ "\n")
   );end of cond option 1
   ((and (/= selectsheetno "") (> (abs (atoi selectsheetno)) (+ shlen 1)) ) 
     (princ "\n invalid sheet no. exceed number of sheets")
   );end of cond option 2
   ((or (= selectsheetno "") (= (abs (atoi selectsheetno)) (+ shlen 1)))
     (setq selectsheetno 1)
     (setq selectsheetname (nth (- selectsheetno 1) SheetNameList))
     (setq sht (vlax-get-property sheets 'Item selectsheetname))
     (setq acsheet (vlax-invoke-method sht 'Activate)) 
     (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
     ;(setq newsheetname (getstring t "\n Adds a sheet to the last position. \n input new sheet name : "))
     (if (/= newsheetname "")
       (progn 
         (if (= (car (member (strcase newsheetname) strcasedlist)) nil)
           (vlax-put-property (vlax-invoke-method Sheets 'Add) 'Name newsheetname)
           (progn
             (princ "\n cannot make with duplicated name. please retry ")
             (setq sht (vlax-get-property sheets 'Item newsheetname))
             (setq acsheet (vlax-invoke-method sht 'Activate)) 
             (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
             (setq acsheetname (vlax-get-property acsheet 'name))
             (princ "\n your new sheet is activated - ")
             (princ acsheetname)
             (exit)
           )
         );end of if
       );end of progn
     );end of if
     (setq sht (vlax-get-property sheets 'Item newsheetname))
     (setq acsheet (vlax-invoke-method sht 'Activate)) 
     (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
     (setq acsheetname (vlax-get-property acsheet 'name))
     (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
     (setq shlen (length sheetnamelist))
     (vlax-invoke-method sht 'move (vlax-get-property sheets "item" shlen))
     (vlax-invoke-method (vlax-get-property sheets 'item (last sheetnamelist)) 'move (vlax-get-property sheets "item" (- shlen 1)))
     (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
     (setq index 0)
     (princ "\n [ Number ] - Sheet Name ")
     (repeat shlen
       (princ "\n [ ")
       (princ (+ index 1))
       (princ " ] - ")
       (princ (nth index sheetnamelist))
       (setq index (+ index 1))
     )
     (princ "\n")
     (vlax-invoke-method sht 'Activate)
     (princ "\n your new sheet is activated - ")
     (princ acsheetname)
     (princ "\n")
   );end of cond option 3
);end of cond
 (vlax-release-object AcSheet)
 (vlax-release-object Sheets)
 (vlax-release-object Workbooks)
 (vlax-release-object ExcelApp)
(setvar "cmdecho" 1)
(princ)
)

(defun c:ECSEL ( / r c )
 (setq r (getint "\n input row number "))
 (setq c (getint "\n input column number "))
 (ex:ecsel r c)
 (vlax-release-object AcSheet)
 (vlax-release-object Sheets)
 (vlax-release-object Workbooks)
 (vlax-release-object ExcelApp)
 (princ)
)

(defun c:ECPUT ( / textstring)
 (setq textstring (getstring t "\n input text for selected cell in excel "))
 (ex:ecput textstring)
 (vlax-release-object AcSheet)
 (vlax-release-object Sheets)
 (vlax-release-object Workbooks)
 (vlax-release-object ExcelApp)
 (princ)
)

(defun c:ECGET ( / textstring )
 (setq textstring (ex:ecget))
 (princ "\n your text in excel - ")
 (princ textstring)
 (vlax-release-object AcSheet)
 (vlax-release-object Sheets)
 (vlax-release-object Workbooks)
 (vlax-release-object ExcelApp)
 (princ)
)


(defun ex:ECSEL ( r c / *error* excelapp workbooks sheets acsheet acsheetname captionname addr rng c1 c2 c3)
 (setvar "cmdecho" 0)
    (defun *error* ( msg )
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\n Error: " msg))
        )
        (vlax-release-object AcSheet)
        (vlax-release-object Sheets)
        (vlax-release-object Workbooks)
        (vlax-release-object ExcelApp)
        (setvar "cmdecho" 1)
        (princ)
    ) 
 ;BIGAL's ah:chkexcel
 (if (= (setq excelapp (vlax-get-object "Excel.Application") ) nil) ; if open already
     (setq excelapp (vlax-get-or-create-object "Excel.Application"))    
 )
 (if (= (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet)) nil)
    (vlax-invoke-method (vlax-get-property excelapp 'Workbooks) 'Add)
 )
 (vlax-put Excelapp "visible" :vlax-true)
 (if (/= (setq captionname (vlax-get-property ExcelApp 'caption)) nil)
    (progn
      (princ "\n workbook name - ")
      (princ captionname)
    );end of progn
 )

 (setq Workbooks (vlax-get-property ExcelApp 'Workbooks))
 (setq Sheets (vlax-get-property ExcelApp 'Sheets))
 (setq AcSheet (vlax-get-property ExcelApp 'ActiveSheet))
 (setq acsheetname (vlax-get-property acsheet 'name))

 (princ "\n active sheet now - ")
 (princ acsheetname)

 (princ "\n your selected cell is - Row ")
 (princ r)
 (princ ", Column ")
 (princ c)
 
 (setq c (- c 1))

 (cond
   ((and (> c -1) (< c 25))
     (setq c1 (+ c 1))
     (setq addr (strcat (chr (+ 64 c1)) (itoa r) ":" (chr (+ 64 c1)) (itoa r) ))
   );end of cond option 1
   ((and (> c 24) (< c 702))
     (setq c2 (fix (/ c 26)))
     (setq c1 (- c (* c2 26)))
     (setq c2 c2)
     (setq c1 (+ c1 1))
     ;(princ "c1 - ")
     ;(princ c1)
     ;(princ "c2 - ")
     ;(princ c2)
     (if (> c2 0)
       (setq addr (strcat (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r) ":" (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r)))
       (setq addr (strcat (chr (+ 64 c1)) (itoa r) ":" (chr (+ 64 c1)) (itoa r) ))
     )
   );end of cond option 2
   ((and (> c 701) (< c 18278))
     (setq c3 (fix (/ c (* 26 26)) ) )
     (setq c2 (fix (/ (- c (* c3 (* 26 26))) 26)))
     (setq c1 (- (- c (* (* c3 26) 26)) (* c2 26)))
     (setq c3 c3)
     (setq c2 c2)
     (setq c1 (+ c1 1))
     ;(princ "c1 - ")
     ;(princ c1)
     ;(princ "c2 - ")
     ;(princ c2)
     ;(princ "c3 - ")
     ;(princ c3)
     (if (> c3 0)
       (setq addr (strcat (vl-princ-to-string (chr (+ 64 c3))) (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1)))  (itoa r) ":" (vl-princ-to-string (chr (+ 64 c3))) (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r)))
       (setq addr (strcat (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r) ":" (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r)))
     )
   );end of cond option 3
 );end of cond
 (princ " ( in address format ")
 (princ addr)
 (princ " )")


 (setq rng (vlax-get-property acsheet 'Range addr))
 (vlax-invoke rng 'Select)



 (setvar "cmdecho" 1)
 (princ)
)



(defun ex:ECPUT ( textstring / *error* excelapp workbooks sheets acsheet acsheetname accell cell r c captionname addr rng textstring2 textstring c1 c2 c3)
 (setvar "cmdecho" 0)
    (defun *error* ( msg )
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\n Error: " msg))
        )
        (vlax-release-object AcSheet)
        (vlax-release-object Sheets)
        (vlax-release-object Workbooks)
        (vlax-release-object ExcelApp)
        (setvar "cmdecho" 1)
        (princ)
    ) 
 ;BIGAL's ah:chkexcel
 (if (= (setq excelapp (vlax-get-object "Excel.Application") ) nil) ; if open already
     (setq excelapp (vlax-get-or-create-object "Excel.Application"))    
 )
 (if (= (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet)) nil)
    (vlax-invoke-method (vlax-get-property excelapp 'Workbooks) 'Add)
 )
 (vlax-put Excelapp "visible" :vlax-true)
 (if (/= (setq captionname (vlax-get-property ExcelApp 'caption)) nil)
    (progn
      (princ "\n workbook name - ")
      (princ captionname)
    );end of progn
 )

 (setq Workbooks (vlax-get-property ExcelApp 'Workbooks))
 (setq Sheets (vlax-get-property ExcelApp 'Sheets))
 (setq AcSheet (vlax-get-property ExcelApp 'ActiveSheet))
 (setq acsheetname (vlax-get-property acsheet 'name))
 (setq accell (vlax-get-property ExcelApp 'Activecell))
 (setq cell (vlax-get-property acsheet 'Cells))

 (setq textstring2 (strcat "'" textstring))

 (setq r (vlax-get-property accell 'row))
 (setq c (vlax-get-property accell 'column))

 (princ "\n active sheet now - ")
 (princ acsheetname)

 (princ "\n your selected cell is - Row ")
 (princ r)
 (princ ", Column ")
 (princ c)

 (setq c (- c 1))

 (cond
   ((and (> c -1) (< c 25))
     (setq c1 (+ c 1))
     (setq addr (strcat (chr (+ 64 c1)) (itoa r) ":" (chr (+ 64 c1)) (itoa r) ))
   );end of cond option 1
   ((and (> c 24) (< c 702))
     (setq c2 (fix (/ c 26)))
     (setq c1 (- c (* c2 26)))
     (setq c2 c2)
     (setq c1 (+ c1 1))
     ;(princ "c1 - ")
     ;(princ c1)
     ;(princ "c2 - ")
     ;(princ c2)
     (if (> c2 0)
       (setq addr (strcat (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r) ":" (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r)))
       (setq addr (strcat (chr (+ 64 c1)) (itoa r) ":" (chr (+ 64 c1)) (itoa r) ))
     )
   );end of cond option 2
   ((and (> c 701) (< c 18278))
     (setq c3 (fix (/ c (* 26 26)) ) )
     (setq c2 (fix (/ (- c (* c3 (* 26 26))) 26)))
     (setq c1 (- (- c (* (* c3 26) 26)) (* c2 26)))
     (setq c3 c3)
     (setq c2 c2)
     (setq c1 (+ c1 1))
     ;(princ "c1 - ")
     ;(princ c1)
     ;(princ "c2 - ")
     ;(princ c2)
     ;(princ "c3 - ")
     ;(princ c3)
     (if (> c3 0)
       (setq addr (strcat (vl-princ-to-string (chr (+ 64 c3))) (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1)))  (itoa r) ":" (vl-princ-to-string (chr (+ 64 c3))) (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r)))
       (setq addr (strcat (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r) ":" (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r)))
     )
   );end of cond option 3
 );end of cond
 (princ " ( in address format ")
 (princ addr)
 (princ " )")
 
 (princ "\n your text - ")
 (princ textstring)

 (setq c (+ c 1))

 (vlax-put-property cell 'item r c textstring2)


 ;(vlax-release-object AcSheet)
 ;(vlax-release-object Sheets)
 ;(vlax-release-object Workbooks)
 ;(vlax-release-object ExcelApp)
 (setvar "cmdecho" 1)
 (princ)
)




(defun ex:ECGET ( / *error* excelapp workbooks sheets acsheet acsheetname accell cell r c captionname addr rng textstring c1 c2 c3 )
 (setvar "cmdecho" 0)
    (defun *error* ( msg )
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\n Error: " msg))
        )
        (vlax-release-object AcSheet)
        (vlax-release-object Sheets)
        (vlax-release-object Workbooks)
        (vlax-release-object ExcelApp)
        (setvar "cmdecho" 1)
        (princ)
    ) 
 ;BIGAL's ah:chkexcel
 (if (= (setq excelapp (vlax-get-object "Excel.Application") ) nil) ; if open already
     (setq excelapp (vlax-get-or-create-object "Excel.Application"))    
 )
 (if (= (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet)) nil)
    (vlax-invoke-method (vlax-get-property excelapp 'Workbooks) 'Add)
 )
 (vlax-put Excelapp "visible" :vlax-true)
 (if (/= (setq captionname (vlax-get-property ExcelApp 'caption)) nil)
    (progn
      (princ "\n workbook name - ")
      (princ captionname)
    );end of progn
 )

 (setq Workbooks (vlax-get-property ExcelApp 'Workbooks))
 (setq Sheets (vlax-get-property ExcelApp 'Sheets))
 (setq AcSheet (vlax-get-property ExcelApp 'ActiveSheet))
 (setq acsheetname (vlax-get-property acsheet 'name))
 (setq accell (vlax-get-property ExcelApp 'Activecell))
 (setq cell (vlax-get-property acsheet 'Cells))

 (setq r (vlax-get-property accell 'row))
 (setq c (vlax-get-property accell 'column))

 (princ "\n active sheet now - ")
 (princ acsheetname)

 (princ "\n your selected cell is - Row ")
 (princ r)
 (princ ", Column ")
 (princ c)

 (setq c (- c 1))

 (cond
   ((and (> c -1) (< c 25))
     (setq c1 (+ c 1))
     (setq addr (strcat (chr (+ 64 c1)) (itoa r) ":" (chr (+ 64 c1)) (itoa r) ))
   );end of cond option 1
   ((and (> c 24) (< c 702))
     (setq c2 (fix (/ c 26)))
     (setq c1 (- c (* c2 26)))
     (setq c2 c2)
     (setq c1 (+ c1 1))
     ;(princ "c1 - ")
     ;(princ c1)
     ;(princ "c2 - ")
     ;(princ c2)
     (if (> c2 0)
       (setq addr (strcat (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r) ":" (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r)))
       (setq addr (strcat (chr (+ 64 c1)) (itoa r) ":" (chr (+ 64 c1)) (itoa r) ))
     )
   );end of cond option 2
   ((and (> c 701) (< c 18278))
     (setq c3 (fix (/ c (* 26 26)) ) )
     (setq c2 (fix (/ (- c (* c3 (* 26 26))) 26)))
     (setq c1 (- (- c (* (* c3 26) 26)) (* c2 26)))
     (setq c3 c3)
     (setq c2 c2)
     (setq c1 (+ c1 1))
     ;(princ "c1 - ")
     ;(princ c1)
     ;(princ "c2 - ")
     ;(princ c2)
     ;(princ "c3 - ")
     ;(princ c3)
     (if (> c3 0)
       (setq addr (strcat (vl-princ-to-string (chr (+ 64 c3))) (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1)))  (itoa r) ":" (vl-princ-to-string (chr (+ 64 c3))) (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r)))
       (setq addr (strcat (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r) ":" (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r)))
     )
   );end of cond option 3
 );end of cond
 (princ " ( in address format ")
 (princ addr)
 (princ " )")

 (setq c (+ c 1))
 ;(setq rng (vlax-get-property acsheet 'Range addr))
 ;(vlax-invoke rng 'Select)
 

 (setq textstring (vlax-variant-value (vlax-get-property (vlax-variant-value (vlax-get-property cell 'item r c)) 'text)))
 
 textstring



)


(defun c:ECADR ( / rclist )
 (setq rclist (ex:ECADR))
 (princ "\n active cell's row and column number by list - ")
 (princ rclist)
 (vlax-release-object AcSheet)
 (vlax-release-object Sheets)
 (vlax-release-object Workbooks)
 (vlax-release-object ExcelApp)
 (princ)
)


(defun ex:ECADR ( / *error* excelapp workbooks sheets acsheet acsheetname accell cell r c captionname addr rng textstring c1 c2 c3 )
 (setvar "cmdecho" 0)
    (defun *error* ( msg )
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\n Error: " msg))
        )
        (vlax-release-object AcSheet)
        (vlax-release-object Sheets)
        (vlax-release-object Workbooks)
        (vlax-release-object ExcelApp)
        (setvar "cmdecho" 1)
        (princ)
    ) 
 ;BIGAL's ah:chkexcel
 (if (= (setq excelapp (vlax-get-object "Excel.Application") ) nil) ; if open already
     (setq excelapp (vlax-get-or-create-object "Excel.Application"))    
 )
 (if (= (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet)) nil)
    (vlax-invoke-method (vlax-get-property excelapp 'Workbooks) 'Add)
 )
 (vlax-put Excelapp "visible" :vlax-true)
 (if (/= (setq captionname (vlax-get-property ExcelApp 'caption)) nil)
    (progn
      (princ "\n workbook name - ")
      (princ captionname)
    );end of progn
 )

 (setq Workbooks (vlax-get-property ExcelApp 'Workbooks))
 (setq Sheets (vlax-get-property ExcelApp 'Sheets))
 (setq AcSheet (vlax-get-property ExcelApp 'ActiveSheet))
 (setq acsheetname (vlax-get-property acsheet 'name))
 (setq accell (vlax-get-property ExcelApp 'Activecell))
 (setq cell (vlax-get-property acsheet 'Cells))

 (setq r (vlax-get-property accell 'row))
 (setq c (vlax-get-property accell 'column))

 (princ "\n active sheet now - ")
 (princ acsheetname)

 (princ "\n your selected cell is - Row ")
 (princ r)
 (princ ", Column ")
 (princ c)

 (setq c (- c 1))

 (cond
   ((and (> c -1) (< c 25))
     (setq c1 (+ c 1))
     (setq addr (strcat (chr (+ 64 c1)) (itoa r) ":" (chr (+ 64 c1)) (itoa r) ))
   );end of cond option 1
   ((and (> c 24) (< c 702))
     (setq c2 (fix (/ c 26)))
     (setq c1 (- c (* c2 26)))
     (setq c2 c2)
     (setq c1 (+ c1 1))
     ;(princ "c1 - ")
     ;(princ c1)
     ;(princ "c2 - ")
     ;(princ c2)
     (if (> c2 0)
       (setq addr (strcat (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r) ":" (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r)))
       (setq addr (strcat (chr (+ 64 c1)) (itoa r) ":" (chr (+ 64 c1)) (itoa r) ))
     )
   );end of cond option 2
   ((and (> c 701) (< c 18278))
     (setq c3 (fix (/ c (* 26 26)) ) )
     (setq c2 (fix (/ (- c (* c3 (* 26 26))) 26)))
     (setq c1 (- (- c (* (* c3 26) 26)) (* c2 26)))
     (setq c3 c3)
     (setq c2 c2)
     (setq c1 (+ c1 1))
     ;(princ "c1 - ")
     ;(princ c1)
     ;(princ "c2 - ")
     ;(princ c2)
     ;(princ "c3 - ")
     ;(princ c3)
     (if (> c3 0)
       (setq addr (strcat (vl-princ-to-string (chr (+ 64 c3))) (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1)))  (itoa r) ":" (vl-princ-to-string (chr (+ 64 c3))) (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r)))
       (setq addr (strcat (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r) ":" (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r)))
     )
   );end of cond option 3
 );end of cond
 (princ " ( in address format ")
 (princ addr)
 (princ " )")

 (setq c (+ c 1))
 ;(setq rng (vlax-get-property acsheet 'Range addr))
 ;(vlax-invoke rng 'Select)
 
 
 (list r c)



)




(princ "\n ESCUR, ESADD, ESDEL, ESUHD / ECSEL, ECPUT, ECGET, ECADR- loading complete")

 

There are many existing lisp that do this,

but I made it easy for newbies like me to understand. by command

It's also for my practice.

 

command

- for SHEET

1. ESCUR - change current Excel sheet
   (ex:escur num) ; sub routine version of ESCUR

2. ESADD - add new Excel sheet

   (ex:esadd "numstring" "namestring") ; sub routine version of ESADD

3. ESDEL - delete Excel sheet

4. ESUHD - unhide all hided sheets at once

 

- for CELL

5. ECSEL - select active cell 

    (ex:ecsel row column) ; sub routine version of ECSEL

6. ECPUT - put text value in active cell

    (ex:ecput "textstring") ; sub routine version of ECPUT

7. ECGET - get text value in active cell, and also get address of active cell

    (setq aaa (ex:ecget)) ; sub routine version of ECGET

8. ECADR - get active cell's address by list (r c)

    (setq rclist (ex:ecadr)) ; sub routine version of ECADR

 

example

command: ESADD 
 active sheet now - Sheet2
 [ Number ] - Sheet Name 
 [ 1 ] - Sheet1
 [ 2 ] - Sheet2
 input order of new sheet (just space bar = add a new sheet at the end) - 
 input new sheet name : TEST_EKKO
 [ Number ] - Sheet Name 
 [ 1 ] - Sheet1
 [ 2 ] - Sheet2
 [ 3 ] - TEST_EKKO
 your new sheet is activated - TEST_EKKO



command: ESADD 
 active sheet now - TEST_EKKO
 [ Number ] - Sheet Name 
 [ 1 ] - Sheet1
 [ 2 ] - Sheet2
 [ 3 ] - TEST_EKKO
 input order of new sheet (just space bar = add a new sheet at the end) - 3
 input new sheet name : TEST2_EKKO
 [ Number ] - Sheet Name 
 [ 1 ] - Sheet1
 [ 2 ] - Sheet2
 [ 3 ] - TEST2_EKKO
 [ 4 ] - TEST_EKKO
 your new sheet is activated - TEST2_EKKO

 

not only variable, but also, in excel, you can see active sheet is changed.

since this Lisp is made to work with the sheet order number 'selectsheetno'

it will be easy to paste into your other Lisp routine's loop

 

if you paste only the active cell part well, you can apply this to the previous post, screenshot Lisp (ssw, ssp)😆

 

 

edit history

+ update ESDEL function. and add BIGAL's code 

+ ESADD : add escape when duplicated sheet name

+ ESADD : if duplicated sheet name, activate that sheet

+ add (ex:esaddmodule)

+ ESCUR : add cannot select hided sheet option

+ ESUHD : add function - unhide all hided sheets at once

+ ALL : add function - make new workbooks when excel is not opened, add release excel routine, print workbook name (caption)

+ ECSEL, ECPUT, ECGET - add cell function for select, put text, get text. command is for example. sub routine is main.

+ ECSEL, ECPUT, ECGET - add address calculation for over the Z column, ZZ column. now it will be calculate correctly in case of address under ZZZ column. 

+ ECSEL, ECPUT, ECGET - edit address calculation.

+ ECADR - add function. 

+ ECSEL, ECPUT, ECGET, ECADR - edit typo this part

   ((and (> c -1) (< c 25))
     (setq addr (strcat (chr (+ 64 c)) (itoa r) ":" (chr (+ 64 c)) (itoa r) ))
   );end of cond option 1
   
      to
   
   ((and (> c -1) (< c 25))
     (setq c1 (+ c 1))
     (setq addr (strcat (chr (+ 64 c1)) (itoa r) ":" (chr (+ 64 c1)) (itoa r) ))
   );end of cond option 1

+ ESCUR - edit typo, separate c:ESCUR and ex:ESCUR

+ ESADD - When the current number of sheets+1 number is entered, the sheet is added at the last position.

 

2022.06.07 edit

add 2 ifs

     (if (> c2 0)
       (setq addr (strcat (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r) ":" (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r)))
       (setq addr (strcat (chr (+ 64 c1)) (itoa r) ":" (chr (+ 64 c1)) (itoa r) ))
     )

;;;;;;;;;;;;;;;

     (if (> c3 0)
       (setq addr (strcat (vl-princ-to-string (chr (+ 64 c3))) (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1)))  (itoa r) ":" (vl-princ-to-string (chr (+ 64 c3))) (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r)))
       (setq addr (strcat (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r) ":" (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r)))
     )
Edited by exceed
  • Thanks 2
Link to comment
Share on other sites

Exceed can replace the subload with some thing like this. No need to check registery. The MS stuff like Excel, Word, Access are like registered applications have seen same with Adobe products. I ahve tried to find a list of the "Applications" with no success.

 

(defun ahchkexcel (filename /  )
(if (= (setq myxl (vlax-get-object "Excel.Application") ) nil) ; if open already
(setq myxl (vlax-get-or-create-object "excel.Application"))    ; open excel
)
do more excel stuff like check filename 
.........
.......

 

 

 

Edited by BIGAL
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

thank you BIGAL. I updated the code above in your way.😀

 

---------------------------------------------------------------------------------------------------------------

On 3/28/2022 at 10:47 AM, BIGAL said:
(defun ahchkexcel (filename /  )
(if (= (setq myxl (vlax-get-object "Excel.Application") ) nil) ; if open already
(setq myxl (vlax-get-or-create-object "excel.Application"))    ; open excel
)
do more excel stuff like check filename 
.........
.......

 

 (if (= (setq excelapp (vlax-get-object "Excel.Application") ) nil) ; if open already
     (setq excelapp (vlax-get-or-create-object "Excel.Application"))    
 )
 (if (= (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet)) nil)
    (vlax-invoke-method (vlax-get-property excelapp 'Workbooks) 'Add)
 )

I attach this in your code.

this will find excel application

- if excel file is opened, lisp uses that excel file

- if excel file is not opened, it opens excel application -> makes new workbooks -> uses that. 

I think this is complete 1 set for others.

except when if lisp uses excel file open method or invisible (not open excel application) method

Edited by exceed
  • Thanks 1
Link to comment
Share on other sites

On 3/28/2022 at 8:53 AM, exceed said:
; ESCUR, ESADD, ESDEL, ESUHD / ECSEL, ECPUT, ECGET - 2022.03.29 exceed
; https://www.cadtutor.net/forum/topic/74681-cad-output-excel-specified-page/#comment-591539

; before you run this lisp - Open both CAD and Excel.
; If multiple Excel windows are open, the top Excel window is selected.
; The order can be changed with Alt+Tab. Place the target Excel window right behind the CAD
; It is NOT executed when a cell value or formula is being edited (in edit mode)
; It is NOT executed when a save prompt is floating, or any other excel dialog box is running.
; please complete all these tasks and run this lisp

; 1. Excel Sheet Control Lisp

; ESCUR - change current excel sheet
; If you enter ESCUR, the sheet name list of the Excel workbook is displayed. 
; when you enter a sheet order number, the active sheet changes to that sheet.
; hidden sheets are included in the list. If you enter a hidden sheet number, 
; you cannot see it before you modify the property, so in this case, another sheet will be selected.

; ESADD - add new excel sheet
; If you enter ESADD, you can select the list of sheets in the current Excel and where to add them. 
; If you press the space bar without entering anything, it will be created at the end. 
; You must enter a sheet name.
; Duplicate name check function is added.

; (ex:esadd "1" "sheetnameyouwant")
; this is sub routine module, for insert ESADD to another lisp
; "1" - means sheet order number. this is string, NOT NUMBER format. it can have "" empty value. this mean add the last sheet.
; "sheetnameyouwnat" - new sheet name. this is string
; example 1
; (ex:esadd "" "MySheet1234")
; this will find MySheet1234 in your Excel Workbook. if it doesn't have that sheet. it will add the last sheet "MySheet1234"
; if it has "MySheet1234", just activate MySheet1234 sheet.
; example 2
; (ex:esadd "3" "MySheet1234")
; find "MySheet1234" and if it doesn't have. add 3rd sheet "MySheet1234", old sheets after 3rd sheet, go to back from 4th sheet.
; if it has "MySheet1234", just activate MySheet1234 sheet.

; ESDEL - delete excel sheet
; Since the Excel workbook has to have at least one sheet, it escapes when there is one left.

; ESUHD - unhide all hided sheets

; 2. Excel Cell Control Lisp

; ECSEL - select active cell command
; visible cursor does not move. but, in Excel, address field in the upper left corner, you can see that the active cell has been changed.
; In practice, you will use it more this way.
; (ex:ecsel r c)
; sub routine version of ECSEL
; r = row, c = column
; activate cell in active sheet.

; ECPUT - put text value in active cell command
; In practice, you will use it more this way.
; (ex:ecput "textstring")
; sub routine version of ECPUT
; can input any text string in active cell. 

; ECGET - get text value in active cell command
; In practice, you will use it more this way.
; (setq aaa (ex:ecget))
; (princ aaa)
; sub routine version of ECGET


(vl-load-com)

(defun c:ESCUR ( / *error* excelapp workbooks sheets acsheet sheetnamelist acsheetname selectsheetno selectsheetname sht shlen index hideunhide captionname)
 (setvar "cmdecho" 0)
    (defun *error* ( msg )
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\n Error: " msg))
        )
        (vlax-release-object AcSheet)
        (vlax-release-object Sheets)
        (vlax-release-object Workbooks)
        (vlax-release-object ExcelApp)
        (setvar "cmdecho" 1)
        (princ)
    ) 
 ;BIGAL's ah:chkexcel
 (if (= (setq excelapp (vlax-get-object "Excel.Application") ) nil) ; if open already
     (setq excelapp (vlax-get-or-create-object "Excel.Application"))    
 )
 (if (= (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet)) nil)
    (vlax-invoke-method (vlax-get-property excelapp 'Workbooks) 'Add)
 )
 (vlax-put Excelapp "visible" :vlax-true)
 (if (/= (setq captionname (vlax-get-property ExcelApp 'caption)) nil)
    (progn
      (princ "\n workbook name - ")
      (princ captionname)
    );end of progn
 )

 (setq Workbooks (vlax-get-property ExcelApp 'Workbooks))
 (setq Sheets (vlax-get-property ExcelApp 'Sheets))
 (setq AcSheet (vlax-get-property ExcelApp 'ActiveSheet))
 (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
 (setq acsheetname (vlax-get-property acsheet 'name))

 (princ "\n active sheet now - ")
 (princ acsheetname)
 ;(princ "\n sheets name list - ")
 ;(princ sheetnamelist)

 (setq shlen (length sheetnamelist))
 (setq index 0)
 (princ "\n [ Number ] - Sheet Name ")
 (repeat shlen
   (setq hideunhide (vlax-get-property (vlax-get-property sheets 'item (nth index sheetnamelist)) 'visible))
   (if (= hideunhide 0)
     (progn 
        (princ "\n [ Hided ] - ") 
        (princ (nth index sheetnamelist))
     )
     (progn 
        (princ "\n [ ")
        (princ (+ index 1))
        (princ " ] - ")
        (princ (nth index sheetnamelist))
     );end of progn
   );end of if
   (setq index (+ index 1))
 )


 (initget 7)
 (setq selectsheetno (getint "\n input sheet number - "))
 (if (= (vlax-get-property (vlax-get-property sheets 'item (nth (- selectsheetno 1) sheetnamelist)) 'visible) 0)
   (progn 
      (setq selectsheetname (nth (- selectsheetno 1) SheetNameList))
      (princ "\n selected sheet name - ")
      (princ (vl-princ-to-string selectsheetname))
      (princ "\n cannot select to current sheet, it is hided sheet.")
      (setq acsheetname (vlax-get-property acsheet 'name))
      (princ "\n activated sheet name - ")
      (princ acsheetname)
      (exit)
   );end of progn
   (progn 
      (setq selectsheetname (nth (- selectsheetno 1) SheetNameList))
      (princ "\n selected sheet name - ")
      (princ (vl-princ-to-string selectsheetname))
      (setq sht (vlax-get-property sheets 'Item selectsheetname))
      (setq acsheet (vlax-invoke-method sht 'Activate)) 
      (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
      (setq acsheetname (vlax-get-property acsheet 'name))
      (princ "\n your selected sheet is activated - ")
      (princ acsheetname)
    );end of progn
 );end of if
 ;(vlax-dump-object acsheet)  ;if you delete ";" in first of this line. can get dump vl property of activated sheet you selected


 (vlax-release-object AcSheet)
 (vlax-release-object Sheets)
 (vlax-release-object Workbooks)
 (vlax-release-object ExcelApp)
 (setvar "cmdecho" 1)
 (princ)
)



(defun c:ESUHD ( / *error* excelapp workbooks sheets acsheet sheetnamelist acsheetname selectsheetno selectsheetname sht shlen index hideunhide hidecount unhideanswer captionname)
 (setvar "cmdecho" 0)
    (defun *error* ( msg )
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\n Error: " msg))
        )
        (vlax-release-object AcSheet)
        (vlax-release-object Sheets)
        (vlax-release-object Workbooks)
        (vlax-release-object ExcelApp)
        (setvar "cmdecho" 1)
        (princ)
    ) 
 ;BIGAL's ah:chkexcel
 (if (= (setq excelapp (vlax-get-object "Excel.Application") ) nil) ; if open already
     (setq excelapp (vlax-get-or-create-object "Excel.Application"))    
 )
 (if (= (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet)) nil)
    (vlax-invoke-method (vlax-get-property excelapp 'Workbooks) 'Add)
 )
 (vlax-put Excelapp "visible" :vlax-true)
 (if (/= (setq captionname (vlax-get-property ExcelApp 'caption)) nil)
    (progn
      (princ "\n workbook name - ")
      (princ captionname)
    );end of progn
 )


 (vlax-put Excelapp "visible" :vlax-true)
 (setq Workbooks (vlax-get-property ExcelApp 'Workbooks))
 (setq Sheets (vlax-get-property ExcelApp 'Sheets))
 (setq AcSheet (vlax-get-property ExcelApp 'ActiveSheet))
 (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
 (setq acsheetname (vlax-get-property acsheet 'name))

 (princ "\n active sheet now - ")
 (princ acsheetname)
 ;(princ "\n sheets name list - ")
 ;(princ sheetnamelist)

 (setq shlen (length sheetnamelist))
 (setq index 0)
 (setq hidecount 0)
 (princ "\n [ Number ] - Sheet Name ")
 (repeat shlen
   (setq hideunhide (vlax-get-property (vlax-get-property sheets 'item (nth index sheetnamelist)) 'visible))
   (if (= hideunhide 0)
     (progn 
        (princ "\n [ Hided ] - ") 
        (princ (nth index sheetnamelist))
        (setq hidecount (+ hidecount 1))
     )
     (progn 
        (princ "\n [ ")
        (princ (+ index 1))
        (princ " ] - ")
        (princ (nth index sheetnamelist))
     );end of progn
   );end of if
   (setq index (+ index 1))
 )

 
 (if (/= hidecount 0)
   (progn
     (princ "\n There's ")
     (princ hidecount)
     (princ " sheets hided. ")
     (setq unhideanswer (strcase (getstring "unhide these all sheet? (Y/N) : ")))
     (cond 
       ((= unhideanswer "Y")
        (setq index 0)
        (repeat shlen
          (setq hideunhide (vlax-get-property (vlax-get-property sheets 'item (nth index sheetnamelist)) 'visible))
          (if (= hideunhide 0)
            (progn 
              (vlax-put-property (vlax-get-property sheets 'item (nth index sheetnamelist)) 'visible -1)
              (princ "\n [ ")
              (princ (+ index 1))
              (princ " ] - ")
              (princ (nth index sheetnamelist))
              (princ " - Unhide Complete")
            )
            (progn 
              (princ "\n [ ")
              (princ (+ index 1))
              (princ " ] - ")
              (princ (nth index sheetnamelist))
            );end of progn
          );end of if
          (setq index (+ index 1))
         ); end of repeat
       ); end of cond option 1
       ((/= unhideanswer "Y")
         (exit)); end of cond option 2
     );end of cond
   );end of progn
   (progn
     (princ "\n There's no hided sheets.")
   );end of progn
 );end of if
 ;(vlax-dump-object acsheet)  ;if you delete ";" in first of this line. can get dump vl property of activated sheet you selected

 (vlax-release-object AcSheet)
 (vlax-release-object Sheets)
 (vlax-release-object Workbooks)
 (vlax-release-object ExcelApp)
 (setvar "cmdecho" 1)
 (princ)
)




(defun c:ESADD ( / *error* excelapp workbooks sheets acsheet sheetnamelist acsheetname shlen index selectsheetno selectsheetname sht newsheetname strcasedlist captionname)
 (setvar "cmdecho" 0)
    (defun *error* ( msg )
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\n Error: " msg))
        )
        (vlax-release-object AcSheet)
        (vlax-release-object Sheets)
        (vlax-release-object Workbooks)
        (vlax-release-object ExcelApp)
        (setvar "cmdecho" 1)
        (princ)
    ) 
 ;BIGAL's ah:chkexcel
 (if (= (setq excelapp (vlax-get-object "Excel.Application") ) nil) ; if open already
     (setq excelapp (vlax-get-or-create-object "Excel.Application"))    
 )
 (if (= (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet)) nil)
    (vlax-invoke-method (vlax-get-property excelapp 'Workbooks) 'Add)
 )
 (if (/= (setq captionname (vlax-get-property ExcelApp 'caption)) nil)
    (progn
      (princ "\n workbook name - ")
      (princ captionname)
    );end of progn
 )

 (vlax-put Excelapp "visible" :vlax-true)
 (setq Workbooks (vlax-get-property ExcelApp 'Workbooks))
 (setq Sheets (vlax-get-property ExcelApp 'Sheets))
 (setq AcSheet (vlax-get-property ExcelApp 'ActiveSheet))
 (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
 (setq acsheetname (vlax-get-property acsheet 'name))

 (princ "\n active sheet now - ")
 (princ acsheetname)
 ;(princ "\n sheets name list - ")
 ;(princ sheetnamelist)

 (setq shlen (length sheetnamelist))
 (setq index 0)
 (princ "\n [ Number ] - Sheet Name ")
 (repeat shlen
   (princ "\n [ ")
   (princ (+ index 1))
   (princ " ] - ")
   (princ (nth index sheetnamelist))
   (setq index (+ index 1))
 )

 (setq strcasedlist (mapcar 'strcase sheetnamelist))



 (setq selectsheetno (getstring "\n input order of new sheet (just space bar = add a new sheet at the end) - "))
 (cond 
   ((and (/= selectsheetno "") (< (abs (atoi selectsheetno)) (+ shlen 1)))
     (setq selectsheetno (abs (atoi selectsheetno)))
     (setq selectsheetname (nth (- selectsheetno 1) SheetNameList))
     (setq sht (vlax-get-property sheets 'Item selectsheetname))
     (setq acsheet (vlax-invoke-method sht 'Activate)) 
     (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
     (setq newsheetname (getstring t "\n input new sheet name : "))
     (if (/= newsheetname "")
       (progn 
         (if (= (car (member (strcase newsheetname) strcasedlist)) nil)
           (vlax-put-property (vlax-invoke-method Sheets 'Add) 'Name newsheetname)
           (progn
             (princ "\n cannot make with duplicated name. please retry ")
             (setq sht (vlax-get-property sheets 'Item newsheetname))
             (setq acsheet (vlax-invoke-method sht 'Activate)) 
             (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
             (setq acsheetname (vlax-get-property acsheet 'name))
             (princ "\n your new sheet is activated - ")
             (princ acsheetname)
             (exit)
           )
         );end of if
       );end of progn
     );end of if
     (setq sht (vlax-get-property sheets 'Item newsheetname))
     (setq acsheet (vlax-invoke-method sht 'Activate)) 
     (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
     (setq acsheetname (vlax-get-property acsheet 'name))
     (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
     (setq shlen (length sheetnamelist))
     (setq index 0)
     (princ "\n [ Number ] - Sheet Name ")
     (repeat shlen
       (princ "\n [ ")
       (princ (+ index 1))
       (princ " ] - ")
       (princ (nth index sheetnamelist))
       (setq index (+ index 1))
     )
     (princ "\n")
     (princ "\n your new sheet is activated - ")
     (princ acsheetname)
     (princ "\n")
   );end of cond option 1
   ((and (/= selectsheetno "") (> (abs (atoi selectsheetno)) shlen) ) 
     (princ "\n invalid sheet no. exceed number of sheets")
   );end of cond option 2
   ((= selectsheetno "")
     (setq selectsheetno 1)
     (setq selectsheetname (nth (- selectsheetno 1) SheetNameList))
     (setq sht (vlax-get-property sheets 'Item selectsheetname))
     (setq acsheet (vlax-invoke-method sht 'Activate)) 
     (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
     (setq newsheetname (getstring t "\n input new sheet name : "))
     (if (/= newsheetname "")
       (progn 
         (if (= (car (member (strcase newsheetname) strcasedlist)) nil)
           (vlax-put-property (vlax-invoke-method Sheets 'Add) 'Name newsheetname)
           (progn
             (princ "\n cannot make with duplicated name. please retry ")
             (setq sht (vlax-get-property sheets 'Item newsheetname))
             (setq acsheet (vlax-invoke-method sht 'Activate)) 
             (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
             (setq acsheetname (vlax-get-property acsheet 'name))
             (princ "\n your new sheet is activated - ")
             (princ acsheetname)
             (exit)
           )
         );end of if
       );end of progn
     );end of if
     (setq sht (vlax-get-property sheets 'Item newsheetname))
     (setq acsheet (vlax-invoke-method sht 'Activate)) 
     (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
     (setq acsheetname (vlax-get-property acsheet 'name))
     (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
     (setq shlen (length sheetnamelist))
     (vlax-invoke-method sht 'move (vlax-get-property sheets "item" shlen))
     (vlax-invoke-method (vlax-get-property sheets 'item shlen) 'move (vlax-get-property sheets "item" (- shlen 1)))
     (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
     (setq index 0)
     (princ "\n [ Number ] - Sheet Name ")
     (repeat shlen
       (princ "\n [ ")
       (princ (+ index 1))
       (princ " ] - ")
       (princ (nth index sheetnamelist))
       (setq index (+ index 1))
     )
     (princ "\n")
     (vlax-invoke-method sht 'Activate)
     (princ "\n your new sheet is activated - ")
     (princ acsheetname)
     (princ "\n")
   );end of cond option 3
);end of cond
 (vlax-release-object AcSheet)
 (vlax-release-object Sheets)
 (vlax-release-object Workbooks)
 (vlax-release-object ExcelApp)
 (setvar "cmdecho" 1)
(princ)
)


(defun c:ESDEL ( / *error* myxl excelapp workbooks sheets acsheet sheetnamelist acsheetname selectsheetno selectsheetname sht shlen index captionname)
 (setvar "cmdecho" 0)
    (defun *error* ( msg )
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\n Error: " msg))
        )
        (vlax-release-object AcSheet)
        (vlax-release-object Sheets)
        (vlax-release-object Workbooks)
        (vlax-release-object ExcelApp)
        (setvar "cmdecho" 1)
        (princ)
    ) 
 ;BIGAL's ah:chkexcel
 (if (= (setq excelapp (vlax-get-object "Excel.Application") ) nil) ; if open already
     (setq excelapp (vlax-get-or-create-object "Excel.Application"))    
 )
 (if (= (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet)) nil)
    (vlax-invoke-method (vlax-get-property excelapp 'Workbooks) 'Add)
 )
 (vlax-put Excelapp "visible" :vlax-true)
 (if (/= (setq captionname (vlax-get-property ExcelApp 'caption)) nil)
    (progn
      (princ "\n workbook name - ")
      (princ captionname)
    );end of progn
 )
 (vlax-put Excelapp "visible" :vlax-true)
 (setq Workbooks (vlax-get-property ExcelApp 'Workbooks))
 (setq Sheets (vlax-get-property ExcelApp 'Sheets))
 (setq AcSheet (vlax-get-property ExcelApp 'ActiveSheet))
 (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
 (setq acsheetname (vlax-get-property acsheet 'name))

 (princ "\n active sheet now - ")
 (princ acsheetname)
 ;(princ "\n sheets name list - ")
 ;(princ sheetnamelist)

 (setq shlen (length sheetnamelist))
 (setq index 0)
 (princ "\n [ Number ] - Sheet Name ")
 (repeat shlen
   (princ "\n [ ")
   (princ (+ index 1))
   (princ " ] - ")
   (princ (nth index sheetnamelist))
   (setq index (+ index 1))
 );end of repeat

 (if (< shlen 2)
   (princ "\n you cannot delete last 1 sheet")
   (progn 

     (initget 7)
     (setq selectsheetno (getint "\n input sheet number you want to delete - "))
     (setq selectsheetname (nth (- selectsheetno 1) SheetNameList))
     (princ "\n selected sheet name to delete - ")
     (princ (vl-princ-to-string selectsheetname))
     (vlax-for item sheets
       (if (= (vlax-get-property item 'Name) selectsheetname)
         (vlax-invoke-method item 'Delete)
       )
     )
     (setq SheetNameList '())
       (vlax-for item Sheets
         (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
       )
     (setq shlen (length sheetnamelist))
     (setq index 0)
     (princ "\n [ Number ] - Sheet Name ")
     (repeat shlen
       (princ "\n [ ")
       (princ (+ index 1))
       (princ " ] - ")
       (princ (nth index sheetnamelist))
       (setq index (+ index 1))
     );end of repeat
   );end of progn
 );end of if
 (vlax-release-object AcSheet)
 (vlax-release-object Sheets)
 (vlax-release-object Workbooks)
 (vlax-release-object ExcelApp)
 (setvar "cmdecho" 1)
 (princ)
)


(defun ex:esadd ( selectsheetno newsheetname / *error* excelapp workbooks sheets acsheet sheetnamelist acsheetname shlen index selectsheetname sht strcasedlist captionname)
 (setvar "cmdecho" 0)
    (defun *error* ( msg )
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\n Error: " msg))
        )
        (vlax-release-object AcSheet)
        (vlax-release-object Sheets)
        (vlax-release-object Workbooks)
        (vlax-release-object ExcelApp)
        (setvar "cmdecho" 1)
        (princ)
    ) 
 ;BIGAL's ah:chkexcel
 (if (= (setq excelapp (vlax-get-object "Excel.Application") ) nil) ; if open already
     (setq excelapp (vlax-get-or-create-object "Excel.Application"))    
 )
 (if (= (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet)) nil)
    (vlax-invoke-method (vlax-get-property excelapp 'Workbooks) 'Add)
 )
 (vlax-put Excelapp "visible" :vlax-true)
 (if (/= (setq captionname (vlax-get-property ExcelApp 'caption)) nil)
    (progn
      (princ "\n workbook name - ")
      (princ captionname)
    );end of progn
 )
 (vlax-put Excelapp "visible" :vlax-true)
 (setq Workbooks (vlax-get-property ExcelApp 'Workbooks))
 (setq Sheets (vlax-get-property ExcelApp 'Sheets))
 (setq AcSheet (vlax-get-property ExcelApp 'ActiveSheet))
 (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
 (setq acsheetname (vlax-get-property acsheet 'name))

 (princ "\n active sheet now - ")
 (princ acsheetname)
 ;(princ "\n sheets name list - ")
 ;(princ sheetnamelist)

 (setq shlen (length sheetnamelist))
 (setq index 0)
 (princ "\n [ Number ] - Sheet Name ")
 (repeat shlen
   (princ "\n [ ")
   (princ (+ index 1))
   (princ " ] - ")
   (princ (nth index sheetnamelist))
   (setq index (+ index 1))
 )

 (setq strcasedlist (mapcar 'strcase sheetnamelist))



 ;(setq selectsheetno (getstring "\n input order of new sheet (just space bar = add a new sheet at the end) - "))
 (cond 
   ((and (/= selectsheetno "") (< (abs (atoi selectsheetno)) (+ shlen 1)))
     (setq selectsheetno (abs (atoi selectsheetno)))
     (setq selectsheetname (nth (- selectsheetno 1) SheetNameList))
     (setq sht (vlax-get-property sheets 'Item selectsheetname))
     (setq acsheet (vlax-invoke-method sht 'Activate)) 
     (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
     ;(setq newsheetname (getstring t "\n input new sheet name : "))
     (if (/= newsheetname "")
       (progn 
         (if (= (car (member (strcase newsheetname) strcasedlist)) nil)
           (vlax-put-property (vlax-invoke-method Sheets 'Add) 'Name newsheetname)
           (progn
             (princ "\n cannot make with duplicated name. please retry ")
             (setq sht (vlax-get-property sheets 'Item newsheetname))
             (setq acsheet (vlax-invoke-method sht 'Activate)) 
             (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
             (setq acsheetname (vlax-get-property acsheet 'name))
             (princ "\n your new sheet is activated - ")
             (princ acsheetname)
             (exit)
           )
         );end of if
       );end of progn
     );end of if
     (setq sht (vlax-get-property sheets 'Item newsheetname))
     (setq acsheet (vlax-invoke-method sht 'Activate)) 
     (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
     (setq acsheetname (vlax-get-property acsheet 'name))
     (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
     (setq shlen (length sheetnamelist))
     (setq index 0)
     (princ "\n [ Number ] - Sheet Name ")
     (repeat shlen
       (princ "\n [ ")
       (princ (+ index 1))
       (princ " ] - ")
       (princ (nth index sheetnamelist))
       (setq index (+ index 1))
     )
     (princ "\n")
     (princ "\n your new sheet is activated - ")
     (princ acsheetname)
     (princ "\n")
   );end of cond option 1
   ((and (/= selectsheetno "") (> (abs (atoi selectsheetno)) shlen) ) 
     (princ "\n invalid sheet no. exceed number of sheets")
   );end of cond option 2
   ((= selectsheetno "")
     (setq selectsheetno 1)
     (setq selectsheetname (nth (- selectsheetno 1) SheetNameList))
     (setq sht (vlax-get-property sheets 'Item selectsheetname))
     (setq acsheet (vlax-invoke-method sht 'Activate)) 
     (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
     ;(setq newsheetname (getstring t "\n input new sheet name : "))
     (if (/= newsheetname "")
       (progn 
         (if (= (car (member (strcase newsheetname) strcasedlist)) nil)
           (vlax-put-property (vlax-invoke-method Sheets 'Add) 'Name newsheetname)
           (progn
             (princ "\n cannot make with duplicated name. please retry ")
             (setq sht (vlax-get-property sheets 'Item newsheetname))
             (setq acsheet (vlax-invoke-method sht 'Activate)) 
             (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
             (setq acsheetname (vlax-get-property acsheet 'name))
             (princ "\n your new sheet is activated - ")
             (princ acsheetname)
             (exit)
           )
         );end of if
       );end of progn
     );end of if
     (setq sht (vlax-get-property sheets 'Item newsheetname))
     (setq acsheet (vlax-invoke-method sht 'Activate)) 
     (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet))
     (setq acsheetname (vlax-get-property acsheet 'name))
     (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
     (setq shlen (length sheetnamelist))
     (vlax-invoke-method sht 'move (vlax-get-property sheets "item" shlen))
     (vlax-invoke-method (vlax-get-property sheets 'item (last sheetnamelist)) 'move (vlax-get-property sheets "item" (- shlen 1)))
     (setq SheetNameList '())
            (vlax-for item Sheets
                (setq SheetNameList (append SheetNameList (list (vla-get-name item))))
            )
     (setq index 0)
     (princ "\n [ Number ] - Sheet Name ")
     (repeat shlen
       (princ "\n [ ")
       (princ (+ index 1))
       (princ " ] - ")
       (princ (nth index sheetnamelist))
       (setq index (+ index 1))
     )
     (princ "\n")
     (vlax-invoke-method sht 'Activate)
     (princ "\n your new sheet is activated - ")
     (princ acsheetname)
     (princ "\n")
   );end of cond option 3
);end of cond
 (vlax-release-object AcSheet)
 (vlax-release-object Sheets)
 (vlax-release-object Workbooks)
 (vlax-release-object ExcelApp)
(setvar "cmdecho" 1)
(princ)
)

(defun c:ECSEL ( / r c )
 (setq r (getint "\n input row number "))
 (setq c (getint "\n input column number "))
 (ex:ecsel r c)
 (vlax-release-object AcSheet)
 (vlax-release-object Sheets)
 (vlax-release-object Workbooks)
 (vlax-release-object ExcelApp)
 (princ)
)

(defun c:ECPUT ( / textstring)
 (setq textstring (getstring t "\n input text for selected cell in excel "))
 (ex:ecput textstring)
 (vlax-release-object AcSheet)
 (vlax-release-object Sheets)
 (vlax-release-object Workbooks)
 (vlax-release-object ExcelApp)
 (princ)
)

(defun c:ECGET ( / textstring )
 (setq textstring (ex:ecget))
 (princ "\n your text in excel - ")
 (princ textstring)
 (vlax-release-object AcSheet)
 (vlax-release-object Sheets)
 (vlax-release-object Workbooks)
 (vlax-release-object ExcelApp)
 (princ)
)


(defun ex:ECSEL ( r c / *error* excelapp workbooks sheets acsheet acsheetname captionname addr rng c1 c2 c3)
 (setvar "cmdecho" 0)
    (defun *error* ( msg )
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\n Error: " msg))
        )
        (vlax-release-object AcSheet)
        (vlax-release-object Sheets)
        (vlax-release-object Workbooks)
        (vlax-release-object ExcelApp)
        (setvar "cmdecho" 1)
        (princ)
    ) 
 ;BIGAL's ah:chkexcel
 (if (= (setq excelapp (vlax-get-object "Excel.Application") ) nil) ; if open already
     (setq excelapp (vlax-get-or-create-object "Excel.Application"))    
 )
 (if (= (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet)) nil)
    (vlax-invoke-method (vlax-get-property excelapp 'Workbooks) 'Add)
 )
 (vlax-put Excelapp "visible" :vlax-true)
 (if (/= (setq captionname (vlax-get-property ExcelApp 'caption)) nil)
    (progn
      (princ "\n workbook name - ")
      (princ captionname)
    );end of progn
 )

 (setq Workbooks (vlax-get-property ExcelApp 'Workbooks))
 (setq Sheets (vlax-get-property ExcelApp 'Sheets))
 (setq AcSheet (vlax-get-property ExcelApp 'ActiveSheet))
 (setq acsheetname (vlax-get-property acsheet 'name))

 (princ "\n active sheet now - ")
 (princ acsheetname)

 (princ "\n your selected cell is - Row ")
 (princ r)
 (princ ", Column ")
 (princ c)

 (cond
   ((< c 27)
     (setq addr (strcat (chr (+ 64 c)) (itoa r) ":" (chr (+ 64 c)) (itoa r) ))
   );end of cond option 1
   ((< c 703)
     (setq c1 (fix (rem c 26)))
     (setq c2 (fix (/ (fix (rem (- c c1) (* 26 26)) ) 26)))
     (setq addr (strcat (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r) ":" (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r)))
   );end of cond option 2
   ((< c 18279)
     (setq c1 (fix (rem c 26)))
     (setq c2 (fix (/ (fix (rem (- c c1) (* 26 26)) ) 26)))
     (setq c3 (fix (/ (fix (rem (- (- c c1) (* c2 26)) (* (* 26 26) 26)) ) (* 26 26))))
     (setq addr (strcat (vl-princ-to-string (chr (+ 64 c3))) (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1)))  (itoa r) ":" (vl-princ-to-string (chr (+ 64 c3))) (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r)))
   );end of cond option 3
 );end of cond
 (princ " ( in address format ")
 (princ addr)
 (princ " )")
 (setq rng (vlax-get-property acsheet 'Range addr))
 (vlax-invoke rng 'Select)



 (setvar "cmdecho" 1)
 (princ)
)



(defun ex:ECPUT ( textstring / *error* excelapp workbooks sheets acsheet acsheetname accell cell r c captionname addr rng textstring2 textstring c1 c2 c3)
 (setvar "cmdecho" 0)
    (defun *error* ( msg )
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\n Error: " msg))
        )
        (vlax-release-object AcSheet)
        (vlax-release-object Sheets)
        (vlax-release-object Workbooks)
        (vlax-release-object ExcelApp)
        (setvar "cmdecho" 1)
        (princ)
    ) 
 ;BIGAL's ah:chkexcel
 (if (= (setq excelapp (vlax-get-object "Excel.Application") ) nil) ; if open already
     (setq excelapp (vlax-get-or-create-object "Excel.Application"))    
 )
 (if (= (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet)) nil)
    (vlax-invoke-method (vlax-get-property excelapp 'Workbooks) 'Add)
 )
 (vlax-put Excelapp "visible" :vlax-true)
 (if (/= (setq captionname (vlax-get-property ExcelApp 'caption)) nil)
    (progn
      (princ "\n workbook name - ")
      (princ captionname)
    );end of progn
 )

 (setq Workbooks (vlax-get-property ExcelApp 'Workbooks))
 (setq Sheets (vlax-get-property ExcelApp 'Sheets))
 (setq AcSheet (vlax-get-property ExcelApp 'ActiveSheet))
 (setq acsheetname (vlax-get-property acsheet 'name))
 (setq accell (vlax-get-property ExcelApp 'Activecell))
 (setq cell (vlax-get-property acsheet 'Cells))

 (setq textstring2 (strcat "'" textstring))

 (setq r (vlax-get-property accell 'row))
 (setq c (vlax-get-property accell 'column))

 (princ "\n active sheet now - ")
 (princ acsheetname)

 (princ "\n your selected cell is - Row ")
 (princ r)
 (princ ", Column ")
 (princ c)

 (cond
   ((< c 27)
     (setq addr (strcat (chr (+ 64 c)) (itoa r) ":" (chr (+ 64 c)) (itoa r) ))
   );end of cond option 1
   ((< c 703)
     (setq c1 (fix (rem c 26)))
     (setq c2 (fix (/ (fix (rem (- c c1) (* 26 26)) ) 26)))
     (setq addr (strcat (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r) ":" (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r)))
   );end of cond option 2
   ((< c 18279)
     (setq c1 (fix (rem c 26)))
     (setq c2 (fix (/ (fix (rem (- c c1) (* 26 26)) ) 26)))
     (setq c3 (fix (/ (fix (rem (- (- c c1) (* c2 26)) (* (* 26 26) 26)) ) (* 26 26))))
     (setq addr (strcat (vl-princ-to-string (chr (+ 64 c3))) (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1)))  (itoa r) ":" (vl-princ-to-string (chr (+ 64 c3))) (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r)))
   );end of cond option 3
 );end of cond
 (princ " ( in address format ")
 (princ addr)
 (princ " )")

 ;(setq rng (vlax-get-property acsheet 'Range addr))
 ;(vlax-invoke rng 'Select)
 
 (princ "\n your text - ")
 (princ textstring)

 (vlax-put-property cell 'item r c textstring)


 ;(vlax-release-object AcSheet)
 ;(vlax-release-object Sheets)
 ;(vlax-release-object Workbooks)
 ;(vlax-release-object ExcelApp)
 (setvar "cmdecho" 1)
 (princ)
)




(defun ex:ECGET ( / *error* excelapp workbooks sheets acsheet acsheetname accell cell r c captionname addr rng textstring c1 c2 c3 )
 (setvar "cmdecho" 0)
    (defun *error* ( msg )
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\n Error: " msg))
        )
        (vlax-release-object AcSheet)
        (vlax-release-object Sheets)
        (vlax-release-object Workbooks)
        (vlax-release-object ExcelApp)
        (setvar "cmdecho" 1)
        (princ)
    ) 
 ;BIGAL's ah:chkexcel
 (if (= (setq excelapp (vlax-get-object "Excel.Application") ) nil) ; if open already
     (setq excelapp (vlax-get-or-create-object "Excel.Application"))    
 )
 (if (= (setq acsheet (vlax-get-property ExcelApp 'ActiveSheet)) nil)
    (vlax-invoke-method (vlax-get-property excelapp 'Workbooks) 'Add)
 )
 (vlax-put Excelapp "visible" :vlax-true)
 (if (/= (setq captionname (vlax-get-property ExcelApp 'caption)) nil)
    (progn
      (princ "\n workbook name - ")
      (princ captionname)
    );end of progn
 )

 (setq Workbooks (vlax-get-property ExcelApp 'Workbooks))
 (setq Sheets (vlax-get-property ExcelApp 'Sheets))
 (setq AcSheet (vlax-get-property ExcelApp 'ActiveSheet))
 (setq acsheetname (vlax-get-property acsheet 'name))
 (setq accell (vlax-get-property ExcelApp 'Activecell))
 (setq cell (vlax-get-property acsheet 'Cells))

 (setq r (vlax-get-property accell 'row))
 (setq c (vlax-get-property accell 'column))

 (princ "\n active sheet now - ")
 (princ acsheetname)

 (princ "\n your selected cell is - Row ")
 (princ r)
 (princ ", Column ")
 (princ c)

 (cond
   ((< c 27)
     (setq addr (strcat (chr (+ 64 c)) (itoa r) ":" (chr (+ 64 c)) (itoa r) ))
   );end of cond option 1
   ((< c 703)
     (setq c1 (fix (rem c 26)))
     (setq c2 (fix (/ (fix (rem (- c c1) (* 26 26)) ) 26)))
     (setq addr (strcat (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r) ":" (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r)))
   );end of cond option 2
   ((< c 18279)
     (setq c1 (fix (rem c 26)))
     (setq c2 (fix (/ (fix (rem (- c c1) (* 26 26)) ) 26)))
     (setq c3 (fix (/ (fix (rem (- (- c c1) (* c2 26)) (* (* 26 26) 26)) ) (* 26 26))))
     (setq addr (strcat (vl-princ-to-string (chr (+ 64 c3))) (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1)))  (itoa r) ":" (vl-princ-to-string (chr (+ 64 c3))) (vl-princ-to-string (chr (+ 64 c2))) (vl-princ-to-string (chr (+ 64 c1))) (itoa r)))
   );end of cond option 3
 );end of cond
 (princ " ( in address format ")
 (princ addr)
 (princ " )")

 ;(setq rng (vlax-get-property acsheet 'Range addr))
 ;(vlax-invoke rng 'Select)
 

 (setq textstring (vlax-variant-value (vlax-get-property (vlax-variant-value (vlax-get-property cell 'item r c)) 'text)))
 
 textstring



)




(princ "\n ESCUR, ESADD, ESDEL, ESUHD / ECSEL, ECPUT, ECGET- loading complete")

 

There are many existing lisp that do this,

but I made it easy for newbies like me to understand. by command

It's also for my practice.

 

command

- for SHEET

1. ESCUR - change current Excel sheet

2. ESADD - add new Excel sheet

   (ex:esadd "numstring" "namestring") ; sub routine version of ESADD

3. ESDEL - delete Excel sheet

4. ESUHD - unhide all hided sheets at once

 

- for CELL

5. ECSEL - select active cell 

    (ex:ecsel row column) ; sub routine version of ECSEL

6. ECPUT - put text value in active cell

    (ex:ecput "textstring") ; sub routine version of ECPUT

7. ECGET - get text value in active cell

    (setq aaa (ex:ecget)) ; sub routine version of ECGET

 

 

example

command: ESADD 
 active sheet now - Sheet2
 [ Number ] - Sheet Name 
 [ 1 ] - Sheet1
 [ 2 ] - Sheet2
 input order of new sheet (just space bar = add a new sheet at the end) - 
 input new sheet name : TEST_EKKO
 [ Number ] - Sheet Name 
 [ 1 ] - Sheet1
 [ 2 ] - Sheet2
 [ 3 ] - TEST_EKKO
 your new sheet is activated - TEST_EKKO



command: ESADD 
 active sheet now - TEST_EKKO
 [ Number ] - Sheet Name 
 [ 1 ] - Sheet1
 [ 2 ] - Sheet2
 [ 3 ] - TEST_EKKO
 input order of new sheet (just space bar = add a new sheet at the end) - 3
 input new sheet name : TEST2_EKKO
 [ Number ] - Sheet Name 
 [ 1 ] - Sheet1
 [ 2 ] - Sheet2
 [ 3 ] - TEST2_EKKO
 [ 4 ] - TEST_EKKO
 your new sheet is activated - TEST2_EKKO

 

not only variable, but also, in excel, you can see active sheet is changed.

since this Lisp is made to work with the sheet order number 'selectsheetno'

it will be easy to paste into your other Lisp routine's loop

 

if you paste only the active cell part well, you can apply this to the previous post, screenshot Lisp (ssw, ssp)😆

 

 

edit history

+ update ESDEL function. and add BIGAL's code 

++ ESADD : add escape when duplicated sheet name

+++ ESADD : if duplicated sheet name, activate that sheet

++++ add (ex:esaddmodule)

+++++ ESCUR : add cannot select hided sheet option

++++++ ESUHD : add function - unhide all hided sheets at once

+++++++ ALL : add function - make new workbooks when excel is not opened, add release excel routine, print workbook name (caption)

++++++++ ECSEL, ECPUT, ECGET - add cell function for select, put text, get text. command is for example. sub routine is main.

+++++++++ ECSEL, ECPUT, ECGET - add address calculation for over the Z column, ZZ column. now it will be calculate correctly in case of address under ZZZ column. 

this is my need,Thank you so much my brother for your sharing,salute to you

  • Like 1
Link to comment
Share on other sites

To exceed yeah its lie a few IF's and But's is it open, is the workkbook  in the current excel session, or open a new. 

 

That is why I wrote my own acad -> excel routines. open, check is open, new etc. Get put cell, pick a range in excel -> pass to Autocad as list. 

Edited by BIGAL
  • Like 1
Link to comment
Share on other sites

4 hours ago, ekko said:

this is my need,Thank you so much my brother for your sharing,salute to you

 

I edit some of that code.

address calculation has some error. ex) 78 column or something

 

This is a kind of 26 base calculation. 

but the column alphabet in excel is slightly different from base calculation.

I didn't know that before.

 

For example, when I think of this as a decimal number,

1 to 9 in 1,2,3,4,5,6,7,8,9,10 there is an invisible 0 in front. 01,02,03,04~10

 

However, since the first column alphabet is A, B, C, D...

the base system cannot be calculated unless 'unknown empty alphabet' exists in front. like ?A, ?B, ?C, ?D...

 

Also, when going from Z to AA, a second piece of evidence is added that something exists before A.

 

If A is 0, then it must start from AA, even if A is omitted. The transition from Z to AA cannot be explained. in this case Z -> BA is correct

If A is 1, there must be an alphabet before A. but in this case. transition from Z to AA is incorrect also. Z -> A? is correct. like 9 -> 10. every transition must have that unknown empty alphabet. that way is not fit to excel column.

 

So I solve that by pushing and pulling the digit of 1 by counting as 0 column.

 

now the calculation is correct.

 

This problem is irrelevant if you only use columns A to Z.

Edited by exceed
  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...