0 Members and 1 Guest are viewing this topic.
Hi all ! is there function to open any excel file if it exist, otherwise create it with path and name are specified in function.
(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) )