Board index » delphi » Excel.ActivieWorkBook doesn't work?

Excel.ActivieWorkBook doesn't work?

Hi,

I am writing an application which copies and pastes an Excel file into
TStringGrid. But when I worked with mulitWorkbooks,
or mulitWorkSheets, I always got and Error "Invalid Index", since I use "1"
to indicate the first WorkBook to work with, such as

Excel: OleVariant;
Sheet: OleVariant;
Book: OleVariant;

Excel := OleGetActiveObject('Excel.Application');
Sheet := Excel.WorkBooks[1].WorkSheets[1]; {It's this line that causes the
error}

I've tried to use "2" and "3", but all gave me the same error.

When I tried with Book := Excel.ActiveWorkBook; I got anther error saying "
Method ActiveWorkBook is not supported by
automation object"

Could someone please point me some direction I could get the current/active
worksheet?

Tks a lot!

Jiang

 

Re:Excel.ActivieWorkBook doesn't work?


<<Jiang:
Sheet := Excel.WorkBooks[1].WorkSheets[1]; {It's this line
that causes the error}

Quote

It works just fine for me, and so does Book :=
ExcelActiveWorkbook, as long as a workbook is actually
open. Is 'OleGetActiveObject' a typo in your post, or are
you using a function of your own to start Excel? If so, it
looks like it might be getting the wrong thing?

--
Deborah Pate (TeamB) http://delphi-jedi.org

  Use Borland servers; TeamB don't see posts via ISPs
  http://www.borland.com/newsgroups/genl_faqs.html

Other Threads