dimmesdale has asked for the wisdom of the Perl Monks concerning the following question:

I have some Win32::OLE code interfacing with Excel, and I get an error when I try to access the select property of the range class. The OLE-Browser validates that range has a selection property, I've done code like this before accessing it, but all of a sudden I'm getting the error (the one in the title).

the code looks like this

my ($rest,$imc); for my $i (0..$Groups+1) { for my $j (15*($i+1)-$Conds..15*($i+1)) { $avg->Range(xl_rowcol_to_cell($j-1,2*$Meas+5))->Select(); $rest = 2*$Meas+4; $imc = 2*$Meas+3; $Xl->ActiveCell->{Value} = "=ABS(RC[-$rest]-RC[-$imc])"; $avg->Range(xl_rowcol_to_cell($j-1,2*$Meas+6))->Select(); $rest = 2*$Meas+3; $imc = 2*$Meas+2; $Xl->ActiveCell->{Value} = "=Abs(RC[-$rest]-RC[-$imc])"; if($i == 0) { $avg->Range(xl_rowcol_to_cell($j-1,2*$Meas+7))->Select(); $rest = 2*$Meas+2; $imc = 2*$Meas+1; $Xl->ActiveCell->{Value} = "=Abs(RC[-$rest]-RC[-$imc])"; } } }

I get a long line of these:

OLE exception from "Microsoft Excel": Unable to get the Select property of the Range class Win32::OLE(0.1502) error 0x800a03ec in METHOD/PROPERTYGET "Select" at dyna.pl line 281 OLE exception from "Microsoft Excel":

Anything wrong with the code? ($Xl is an excel object made with Win32::OLE->new, $avg is a worksheet--I write on it elsewhere/do some formatting and it works, so I know that isn't the problem)

Replies are listed 'Best First'.
Re: Unable to get the select property of the range class...
by jsprat (Curate) on Jul 30, 2002 at 18:55 UTC
    Hello again, dimmesdale. You've come a long way with OLE!

    About the error - the syntax looks fine. Have you checked the return value of xl_rowcol_to_cell? IME, it looks like the error Excel gives when you try to select a range that extends outside the worksheet. I'd print the results of xl_rowcol_to_cell and make sure that it returns what you think it should.

      That's what I thought (and it may have been).

      (Thanks)

      I changed it to this (I realized I didn't need the select() method to do the rc[-3] type thing) and it worked fine:

      $rest = 2*$Meas+4; $imc = 2*$Meas+3; $avg->Range(xl_rowcol_to_cell($j-1,2*$Meas+5))->{Value} = "=ABS(RC[-$rest]-RC[-$imc])"; ..etc..