On Thu, 12 Jun 2003, Charbeneau, Chuck wrote: > > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > > Subject: Win32::OLE and Excel Sorting > > > heres one for u folks to get ur heads around - cos its doin mine in > > > > keeps throwing range method error in OLE > > > The problem lies in the definition of the method, and how you are using it. > The Excel Ole Server expects that sort be used: > > EXPRESSION->Sort (<blah>); > > where EXPRESSION is a range object, _not_ a sheet object. > > The following worked for me using random data in the first 9 cells of the > first three columns. In the example, I only selected a few cells to sort in > my selection. You could select the entire sheet, just a column, whatever, > it just needs to be a range object that you are sorting. > > <code> > use strict; > > use Win32::OLE qw(in with); > use Win32::OLE::Const 'Microsoft Excel'; > use Win32::OLE::Variant; > use Win32::OLE::NLS qw(:LOCALE :DATE); > > $Win32::OLE::Warn = 3; # Die on Errors. > > my $Excel = Win32::OLE->GetActiveObject('Excel.Application') > || Win32::OLE->new('Excel.Application', 'Quit'); > $Excel->{DisplayAlerts}=0; > > my $sheet = $Excel->{ActiveSheet}; > my $vtfalse = Variant(VT_BOOL, 0); > > my $SortOrd1 = $sheet->Range("A1:A9"); > my $SortOrd2 = $sheet->Range("C1:C9"); > my $SortOrd3 = $sheet->Range("b1:b9"); > > #IMPORTANT LINE > my $Selection = $sheet->Range("A1:c9"); > > $Selection->Sort({Key1 => $SortOrd1, > Order1 => xlDescending, > Key2 => $SortOrd2, > Order2 => xlDescending, > Key3 => $SortOrd3, > Order3 => xlAscending, > }); > </code> >
Yhe OP's code was missing: use Win32::OLE::Const 'Microsoft Excel'; And yet he used the xl... constants. for descedning, etc. **** [EMAIL PROTECTED] <Carl Jolley> **** All opinions are my own and not necessarily those of my employer **** _______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs