If the error persists, or try this shorter routine as an alternative without using COM API.
Its just a simpler algorithm merely sorting each row of TEXT from top to bottom.
since it does not collect line coordinates and the output just a normal 'csv' file, so don't expect auto cell formatting, column size, alignment etc..
however you still can format cell easily in EXCEL sheet & rename as .xls.
(defun c:tt (/ *error* foo ss fn f a b l ls l1 lst) ;hanhphuc 28.10.2019
(defun *error* (msg)
(if (and f (= (type f) 'FILE))
(close f)
(setq f nil)
)
)
(and (setq foo '((a b) (cdr (assoc a (entget b))))
ss (ssget '((0 . "TEXT") (8 . "Text")))
)
(setq l (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))) ; (acet-ss-to-list ss)
(setq fuzz (* 0.25 (foo 40 (car l)))
ls (mapcar ''((x) (cons (foo 1 x) (foo 10 x))) l)
)
(setq fn (vl-filename-mktemp "table.csv") )
(setq f (open fn "w"))
(setq l nil
sl (vl-sort ls
''((a b)
(if
(equal (caddr a) (caddr b) fuzz)
(< (cadr a) (cadr b))
(< (caddr a) (caddr b))
)
)
)
a (caddar sl)
)
(foreach x sl
(if (equal a (setq b (caddr x)) fuzz)
(setq l1 (cons x l1)
a b
)
(setq l1 (vl-list* x nil l1))
)
(setq a b)
) ;_ end of foreach
(foreach x (progn (foreach x l1
(if x
(setq l (cons x l))
(setq lst (cons l lst)
l nil
)
)
)
(setq lst (cons l lst))
(reverse (vl-remove nil lst))
) ; progn
(write-line (apply 'strcat (mapcar ''((x) (strcat x ",")) (mapcar 'car x))) f)
)
(progn (if f
(close f)
)
(vl-cmdf "start" fn) ; or (vl-cmdf "shell" fn) doesn't work if same filename opened i.e:locked for editting
;(startapp "notepad" fn) ; recommand to use this for mutiple files
)
) ;and
(princ)
)
(or
(wcmatch (strcase (getvar 'dwgname)) "*COORDINATE TABLE 1*")
(alert
"\nThis routine only tested in 'COORDINATE TABLE 1.dwg',
\nPlease download at \nhttps://www.cadtutor.net/forum/topic/68979-export-cad-text-table-in-excel-get-error/"
)
)
(princ)
p/s: In case you have any blank cell in Table, just replace it with "-" or any TEXT!
i.e. TEXT in each Cell in a Row must have content & aligned horizontally in WCS, otherwise texts merge from first column to next