BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

A Sort issue with Excel 2000

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation
View previous topic :: View next topic  
Author Message
M.E.
Guest





PostPosted: Fri Jul 21, 2006 4:00 am    Post subject: A Sort issue with Excel 2000 Reply with quote



Still struggling to understand those differences among Excel versions, I am
getting an EOleSysError of invalid number of parameters with this sort
method with Excel 2000, although it works perfectly with Excel 97 and Excel
2003.

DadosCriacao := PlanilhaRed.Range['A1:P' + Trim(IntToStr(Contagem))];

DadosCriacao.Sort(
DadosCriacao.Range['P2'], // Key1,
xlDescending, // Order1,
DadosCriacao.Range['O2'], // Key2,
EmptyParam, // Type
xlDescending, // Order2,
DadosCriacao.Range['E2'], // Key3,
xlDescending, // Order3,
xlGuess, // Header,
1, // OrderCustom,
False, // MatchasCase,
xlTopToBottom, // Orientation,
EmptyParam, // SortMethod,
EmptyParam, // IgnorcontrolCharacters,
EmptyParam, // IgnoreDiacritics,
EmptyParam // IgnoreKashida
);

Why would the parameters be different in an intermediate version of
Excel??!!
What is missing or exceeding?
Thanks,
Marcio
Back to top
Oliver Townshend
Guest





PostPosted: Fri Jul 21, 2006 4:18 am    Post subject: Re: A Sort issue with Excel 2000 Reply with quote



Quote:
Why would the parameters be different in an intermediate version of
Excel??!!
What is missing or exceeding?

If you look at the different type libraries that Delphi can generate, you
may see different methods for the same feature. I don't remember any
differences with Sort, but they might be there.

The alternative when late binding doesn't work is to use early binding, i.e.
a Variant. It's a bit slower but it can work. Define DadosCriacao as
OleVariant and see if your routine works.

Oliver Townshend
Back to top
M.E.
Guest





PostPosted: Fri Jul 21, 2006 4:25 am    Post subject: Re: A Sort issue with Excel 2000 Reply with quote



Oliver,
It was already... Sad
I'll try to record a macro to see what Excel 2000 does.
Marcio

"Oliver Townshend" <oliveratzipdotcomdotau> escreveu na mensagem
news:44c00f32 (AT) newsgroups (DOT) borland.com...
> Define DadosCriacao as OleVariant and see if your routine works.
Back to top
M.E.
Guest





PostPosted: Fri Jul 21, 2006 4:45 am    Post subject: Re: A Sort issue with Excel 2000 Reply with quote

This is what I got recording a macro

Selection.Sort Key1:=Range("P2"),
Order1:=xlDescending,
Key2:=Range("O2"),
Order2:=xlDescending,
Key3:=Range("E2"),
Order3:=xlAscending,
Header:=xlGuess,
OrderCustom:=1,
MatchCase:=False,
Orientation:=xlTopToBottom

Nevertheless, the sort method failed with this code, which seemed to me to
be right:

DadosCriacao.Sort(
DadosCriacao.Range['P2'], // Key1,
xlDescending, // Order1,
DadosCriacao.Range['O2'], // Key2,
xlDescending, // Order2,
DadosCriacao.Range['E2'], // Key3,
xlDescending, // Order3,
xlGuess, // Header,
1, // OrderCustom,
False, // MatchCase,
xlTopToBottom // Orientation,
);

Any hint?
Marcio

"M.E." <noone (AT) noserver (DOT) com> escreveu na mensagem
> I'll try to record a macro to see what Excel 2000 does.
Back to top
Oliver Townshend
Guest





PostPosted: Fri Jul 21, 2006 4:46 am    Post subject: Re: A Sort issue with Excel 2000 Reply with quote

Quote:
Oliver,
It was already... Sad

Oh well, in that case declare it as a Range and see what happens.

Oliver Townshend
Back to top
Oliver Townshend
Guest





PostPosted: Fri Jul 21, 2006 5:05 am    Post subject: Re: A Sort issue with Excel 2000 Reply with quote

Quote:
DadosCriacao.Sort(
DadosCriacao.Range['P2'], // Key1,
xlDescending, // Order1,
DadosCriacao.Range['O2'], // Key2,
xlDescending, // Order2,
DadosCriacao.Range['E2'], // Key3,
xlDescending, // Order3,
xlGuess, // Header,
1, // OrderCustom,
False, // MatchCase,
xlTopToBottom // Orientation,
);

What is DadosCriacao really? You're using it to define your ranges and your
selection, which is a contradiction. If DadosCriacao is a worksheet, then
you should do something like:

DadosCriacao.Selection.Sort(
DadosCriacao.Range['P2'], // Key1,
xlDescending, // Order1,
DadosCriacao.Range['O2'], // Key2,
xlDescending, // Order2,
DadosCriacao.Range['E2'], // Key3,
xlDescending, // Order3,
xlGuess, // Header,
1, // OrderCustom,
False, // MatchCase,
xlTopToBottom // Orientation,
);
Back to top
M.E.
Guest





PostPosted: Fri Jul 21, 2006 5:18 am    Post subject: Re: A Sort issue with Excel 2000 Reply with quote

Oliver,
DadosCriacao is just a range:
DadosCriacao := PlanilhaRed.Range['A1:P' + Trim(IntToStr(Contagem))];
PlanilhaRed is the sheet.
What I don't get is this code works fine for Excel 97 and Excel 2003!!!
How then would I define a selection? BTW, I'm not using TExcelApplication,
but calling CreateOleObject('Excel.Application'). I never knew which one is
early which is late binding. :/
Thanks a lot for your help.
Marcio

"Oliver Townshend" <oliveratzipdotcomdotau> escreveu na mensagem >

Quote:
What is DadosCriacao really? You're using it to define your ranges and
your
selection, which is a contradiction.
Back to top
Oliver Townshend
Guest





PostPosted: Fri Jul 21, 2006 6:18 am    Post subject: Re: A Sort issue with Excel 2000 Reply with quote

Quote:
What I don't get is this code works fine for Excel 97 and Excel 2003!!!
How then would I define a selection? BTW, I'm not using TExcelApplication,
but calling CreateOleObject('Excel.Application'). I never knew which one
is
early which is late binding. :/

That's late binding. Early binding is normally faster, and provides syntax
checking, code completion and other features which I normally prefer.

Oliver Townshend
Back to top
M.E.
Guest





PostPosted: Fri Jul 21, 2006 7:07 am    Post subject: Re: A Sort issue with Excel 2000 Reply with quote

Oliver,
I must thank you for all your orientation. I'll try to change it later to
early binding.
By now, this is how I made it work. Is there a way to simplify things?

DadosCriacao := PlanilhaRed.Range['A1:P' + Trim(IntToStr(Contagem))];
Excel.Sheets['Redatores'].Select;
XLSSelection := Excel.Selection;
XLSSelection.Sort(
DadosCriacao.Range['P2'], // Key1,
xlDescending, // Order1,
DadosCriacao.Range['O2'], // Key2,
EmptyParam, // Type
xlDescending, // Order2,
DadosCriacao.Range['E2'], // Key3,
xlDescending, // Order3,
xlGuess, // Header,
1, // OrderCustom,
False, // MatchCase,
xlTopToBottom // Orientation,
);
end;

Thank you very, very much.
Marcio


"Oliver Townshend" <oliveratzipdotcomdotau> escreveu:
Quote:
That's late binding. Early binding is normally faster, and provides
syntax
checking, code completion and other features which I normally prefer.
Back to top
Oliver Townshend
Guest





PostPosted: Fri Jul 21, 2006 8:12 am    Post subject: Re: A Sort issue with Excel 2000 Reply with quote

The following might work, but is it simpler? I don't know:

Excel.Sheets['Redatores'].Select;
Excel.Selection.Sort(

...

It only saves one line.

Oliver



"M.E." <noone (AT) noserver (DOT) com> wrote in message
news:44c0373b (AT) newsgroups (DOT) borland.com...
Quote:
Oliver,
I must thank you for all your orientation. I'll try to change it later to
early binding.
By now, this is how I made it work. Is there a way to simplify things?

DadosCriacao := PlanilhaRed.Range['A1:P' + Trim(IntToStr(Contagem))];
Excel.Sheets['Redatores'].Select;
XLSSelection := Excel.Selection;
XLSSelection.Sort(
DadosCriacao.Range['P2'], // Key1,
xlDescending, // Order1,
DadosCriacao.Range['O2'], // Key2,
EmptyParam, // Type
xlDescending, // Order2,
DadosCriacao.Range['E2'], // Key3,
xlDescending, // Order3,
xlGuess, // Header,
1, // OrderCustom,
False, // MatchCase,
xlTopToBottom // Orientation,
);
end;

Thank you very, very much.
Marcio


"Oliver Townshend" <oliveratzipdotcomdotau> escreveu:
That's late binding. Early binding is normally faster, and provides
syntax
checking, code completion and other features which I normally prefer.

Back to top
Oliver Townshend
Guest





PostPosted: Fri Jul 21, 2006 8:12 am    Post subject: Re: A Sort issue with Excel 2000 Reply with quote

Quote:
I must thank you for all your orientation. I'll try to change it later to
early binding.

When you do, you might want to read up on refactoring before you do. It may
not be worth the effort if it works.

Oliver Townshend
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.