PDA

View Full Version : Problems invoking excel methods from lisp


mweaver
2009-08-07, 03:27 AM
I am working on an application that drags information from excel with vlisp. Excel has an intersect method I want to invoke, but can't seem to get the syntax correct. The excel help has the following example:
Application.Intersect(Range("rg1"), Range("rg2"))
I have the following:
_24$ (cdr (nth 6 rangenames))
#<VLA-OBJECT Name 1f93f58c>
_24$ (cdr (nth 21 rangenames))
#<VLA-OBJECT Name 14a849c4>
_24$ (vlax-invoke-method excelapp 'intersect (cdr (nth 21 rangenames))(cdr (nth 6 rangenames)))
; error: Automation Error. Intersect method of Application class failed
I've also tried:
(vlax-invoke-method excelapp 'intersect (list (cdr (nth 21 rangenames))(cdr (nth 6 rangenames))))
; error: too few actual parameters
Do I need to pass my range arguments in a safearray?
Any help would be appreicated.
Mike

peter
2009-08-07, 02:00 PM
Here is a function for creating the safearray. Use the vlax-object.

Use the (vlax-dump-object obj T) function to check the number of parameters you need to call the function from vl.

Your error in your second attempt says too FEW arguments, which points to the first attempt as being more accurate.

Good luck.

You can also try the (vlax-invoke obj "intersect" range1 range2) syntax, maybe?

Peter

; This function creates a variant safearray from a list and the safearray type symbol
; for example: (listtovariantsafearray vlax-vbinteger (list 0) )
(defun ListToVariantSafeArray (symSafeArrayType lstItems / safArray)
(setq safArray (vlax-make-safearray symSafeArrayType (cons 0 (1- (length lstItems)))))
(vlax-safearray-fill safArray lstItems)
(variant safArray))

;vlax-vbInteger (2) Integer
;vlax-vbLong (3) Long integer
;vlax-vbSingle (4) Single-precision floating-point number
;vlax-vbDouble (5) Double-precision floating-point number
;vlax-vbString (8) String
;vlax-vbObject (9) Object
;vlax-vbBoolean (11) Boolean
;vlax-vbVariant (12) Variant

mweaver
2009-08-07, 03:39 PM
I found my problem:Oops: What I thought were ranges were really names. When I used their referstorange property then intersect worked:
(setq temp (vlax-invoke
excelapp
"Intersect"
(vlax-get-property (cdr (nth 21 rangenames)) 'referstorange)
(vlax-get-property (cdr (nth 8 rangenames)) 'referstorange)
)
)