Author Topic: Excel library subs  (Read 36855 times)

0 Members and 1 Guest are viewing this topic.

adalea03

  • Guest
Re: Excel library subs
« Reply #60 on: March 30, 2012, 04:42:41 PM »
Thanks Gile,

Not as hard as I thought.
I cant test it until Monday, though.
No Cad or Excel here.

Have a great weekend.
Tony

codered8x

  • Guest
Re: Excel library subs
« Reply #61 on: April 27, 2012, 04:35:44 AM »
Hi all ! is there function to open any excel file if it exist, otherwise create it with path and name are specified in function.

fixo

  • Guest
Re: Excel library subs
« Reply #62 on: April 27, 2012, 03:30:38 PM »
Hi all ! is there function to open any excel file if it exist, otherwise create it with path and name are specified in function.

You can try this code, just change your logic to suit:

Code: [Select]
(defun C:XLO(/ as gkw newpath path xlapp xlbook xlbooks xlcell xlrange xlsheet xlsheets)
      (vl-load-com)
 
    (alert "I recommend to choose \"Add\" first")
 
     (setq xlapp (xlgetapp))
 
  (_set xlapp 'visible :vlax-false)

   ;;(xlbooksaveas xlbook path)
 
  (if (xlhasbooks xlapp)
     (setq xlbook (xlgetactivebook xlapp))
    (progn
      (initget 1 "Add Open")
      (setq gkw (getkword "\nAdd new Excel document or Open existing file? [Add/Open] <Add> : "))
      (if (eq "Open" gkw)
(progn
     (setq path (getfiled "Select Excel file :"   (getvar "dwgprefix")   "xls;xlsx"  16))
     (setq xlbooks (xlgetbooks xlapp))
     (setq xlbook (xlopenbook xlbooks path))
     (setq xlbook (xlgetactivebook xlapp))
     )
     (progn
     (setq as T)
     (setq xlbook (xladdbook xlapp))
     (setq xlbook (xlgetactivebook xlapp))
     ))))

     (xlshout xlapp :vlax-true)

;| do your work here |;
;;;     (setq xlsheets (xlgetsheets xlbook))
;;;     (setq xlsheet (xlgetsheet xlsheets 1)) ;or any sheet name
;;;     (setq xlsheet  (xlactivate xlsheet))
;;;     (_set xlapp 'visible :vlax-true)
 
  (if (not as)
      (progn
(xlbooksave xlbook)
(xlbookclose xlbook nil))
      (progn
(setq newpath (getfiled "To save Enter file name w/o extension:"
(getvar "dwgprefix")
"xls;xlsx"
1))
(if newpath
  (xlbooksaveas xlbook newpath)
  (progn
    (xlshout xlapp :vlax-false)
  (xlbookclose xlbook nil))
  )
)
      )
     ;|next three lines of code are constant for all programs which will be use 'XLFIXOLIB' library |;
 
     (xlshout xlapp :vlax-true); - 1
 
     (xlquit xlapp); - 2
       
     (xlcleanup  (list xlcell xlrange xlsheet xlsheets xlbook xlapp)); - 3
   
     (setq xlapp nil)
 
  (princ)
  )

~'J'~

codered8x

  • Guest
Re: Excel library subs
« Reply #63 on: April 28, 2012, 02:24:21 PM »
Thank Fixo, special for your library file, it help me so much  :laugh:

fixo

  • Guest
Re: Excel library subs
« Reply #64 on: April 28, 2012, 02:39:38 PM »
I'm glad if this helps to somebody
Happy computing :)

~'J'~

Added latest release of xl library

« Last Edit: December 18, 2013, 12:13:25 PM by fixo »