Hello all,
I am trying to writing some data to an Excel (2002) spreadsheet using LISP
(ACAD 2004). I know, I know, its much easier with VBA, but I unfortunately
don't know VBA. So it's got to be LISP.
I think I'm doing everything right up to the point where I send a variant
array to an Excel range. ACAD gives me the error "error: Automation Error.
Description was not provided."
I'm missing something here. Can anybody help? either with the code below
or by pointing me to a good resource that I can use to figure this out?
Help, as always, is GREATLY appreciated.
(vl-load-com)
(if (not excm-open)
(vlax-import-type-library
:tlb-filename "C:/Program Files/Microsoft Office/Office10/Excel.exe"
:methods-prefix "msxl-"
:properties-prefix "msxl-"
:constants-prefix "msxl-")
)
(setq ExcelApp (vlax-get-or-create-object "Excel.Application")
ExcelWBC (vlax-get-property ExcelApp 'WorkBooks)
NewWB (vlax-invoke-method ExcelWBC 'add)
);setq
(vlax-put-property ExcelApp 'visible 1)
(setq NewWS (vlax-get-property NewWB 'worksheets)
NewWS# (vlax-get-property NewWS 'item wkst#)
Start "A"
End (if (< (/ (length (car lst)) 26) 1)
(chr (+ 64 (length (car lst))))
(strcat (chr (+ 64 (/ (length (car lst)) 26)))
(chr (+ 64 (fix (* 26 (- (/ (length (car lst)) 26.0) (/
(length (car lst)) 26))))))))
Range (strcat Start "1:" End "1")
sfarray (vlax-make-safearray vlax-vbVariant (cons 1 (length (car
lst))))
);setq
(setq lst1 (mapcar '(lambda (x) (mapcar 'vlax-make-variant x)) lst))
(setq counter 1)
(foreach n lst1
(vlax-safearray-fill sfarray n)
(setq vsfarray (vlax-make-variant sfarray)
oRng (msxl-get-range NewWS# Range)
);setq
(msxl-put-value oRng sfarray) ;;;;;;;;; This is where my problem is.
(setq counter (1+ counter))
(setq Range (strcat "A" (itoa counter) ":" (substr range 4 1) (itoa
counter)))
(vlax-release-object oRng)
);foreach
;; Release all object and close Excel.
(vlax-release-object oRng)
(vlax-release-object NewWS#)
(vlax-release-object NewWS)
(vlax-release-object NewWB)
(msxl-saveas ExcelWBC fname nil nil nil nil nil nil)
Fraser Atkinson
CleatusSnow@magma.ca