Author Topic: Using the Item Method when Interfacing with Excel  (Read 2278 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Using the Item Method when Interfacing with Excel
« on: August 20, 2009, 08:34:36 AM »
I have been trying to work with Excel using Visual LISP, but my attempts have been pretty poor so far...

I cannot seem to get the "Item" method to work at all - I am trying to activate a specific Worksheet within a specific Workbook, (without the need to cycle through all the objects in a collection).

I have tried something like this, but keep getting "Error: Member not Found.":

Code: [Select]
(setq xlApp (vlax-get-or-create-object "Excel.Application"))

               (setq Sht (vlax-invoke
                            (vlax-get-property
                              (vlax-invoke
                                (vlax-get-property xlApp 'Workbooks)
                                "Add")
                              'Sheets)
                            'Item "Sheet1"))

Any help is appreciated.

pkohut

  • Guest
Re: Using the Item Method when Interfacing with Excel
« Reply #1 on: August 20, 2009, 09:21:31 AM »
Took a bit thrashing, but got it figured out.

(defun c:abc (/)
  (setq xlApp (vlax-get-or-create-object "Excel.Application"))
  (setq xlWbks (vlax-get-property xlApp 'WorkBooks)) 
  (setq xlShts (vlax-get-property (vlax-invoke xlWbks "Add") 'Sheets))
  (setq xlItem (vlax-get-property xlShts "Item" "Sheet1"))
)

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Using the Item Method when Interfacing with Excel
« Reply #2 on: August 20, 2009, 09:51:10 AM »
Thanks Paul,

Ahh, so Item is a property... not a method  :ugly:

Cheers,

Lee