2003 -> 2000 incompatability

  • Thread starter Thread starter Dale Fye
  • Start date Start date
D

Dale Fye

I've got an Excel application that was written in 2003. Now I find out I
have a user that is still using 2000, and at least one segment of my 2003
code is not working. I have a routine that selects a worksheet, and sorts it
by a particular field. When this user runs this code, it bomb on the last
line of the code provided below.

Selection.Sort Key1:=Range("A2"), _
Order1:=xlAscending, _
Header:=xlYes, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

I don't know whether this is because Excel 9.0 is not recognizing the
DataOption1 or the xlSortNormal, or something else in the Sort method. Would
greatly appreciate if someone could provide the correct code to run this in
Excel 9.0.

Thanks.
 
Remove arguments OrderCustom:=1 and DataOption1:=xlSortNormal which are n/a
in XL2000.

If required, you can make version specific functions by placing the code
that won't be recognized in say XL2000 in a module that will only contain
procedures that will be called in later versions.

Regards,
Peter T
 
DataOption# was added in xl2002. Remove that line (and the preceding line
continuation characers) and it should work in xl2k.
 
Thanks, Peter. I'll take a look.
--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 
if it's just sort routine causing problems then you could test for excel
version - something like:(not tested)

With Selection
If Val(Application.Version) < 11 Then
.Sort Key1:=Range("A2"), _
Order1:=xlAscending, _
Header:=xlYes, _
MatchCase:=False, _
Orientation:=xlTopToBottom
Else
.Sort Key1:=Range("A2"), _
Order1:=xlAscending, _
Header:=xlYes, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End If
End With
However, if more than this then follow Peter T suggestion.
 
Dave was right, only need to remove the DataOption1 argument, OrderCustom
works in XL2000 (contrary to what I had suggested)

If using the application specific If test as suggested by John, and the
module is headed Option Explicit, change xlSortNormal to its intrinsic
Constant value (in the immediate window ?xlSortNormal and hit enter)

Regards,
Peter T
 
I don't think that this will compile in xl2k. That DataOption1 portion will
cause a compile error.

There are workarounds, though.

if val(application.version) < 11 then
'do the sort right here
else
'call a routine in a different module that is written for xl2002+
end if

By having the routine in a different module, xl2k won't even try to compile it.
 
Hi Dave,
Earlier I suggested pretty much the same as you as to how to cater for
multiple versions.
But somewhat to my surprise John's example does compile in my XL2k providing
xlSortNormal is changed to its appropriate number.

Regards,
Peter T
 
Hi Peter,
I had tried my suggested approach awhile ago for desktops using different
versions of Excel and much to my suprise, it worked. I think it's just one of
the Excel VBA quirks - you never know until you give it a go! However and as
I also stated, if changes required were more than just resolving sort routine
problem, Dale should follow your suggestion.
--
JB


Peter T said:
Hi Dave,
Earlier I suggested pretty much the same as you as to how to cater for
multiple versions.
But somewhat to my surprise John's example does compile in my XL2k providing
xlSortNormal is changed to its appropriate number.

Regards,
Peter T
 
Did you change xlSortNormal to a number, I assume so if you had included
Option Explicit

Regards,
Peter T

john said:
Hi Peter,
I had tried my suggested approach awhile ago for desktops using different
versions of Excel and much to my suprise, it worked. I think it's just one of
the Excel VBA quirks - you never know until you give it a go! However and as
I also stated, if changes required were more than just resolving sort routine
problem, Dale should follow your suggestion.
 
Peter,
sorry, I did not mean for a sort routine (which is why I put untested) I
always would use Option Explicit. My suggestion was to offer an idea that
could be taken by Dale to help him on his way solve the problem. Although it
does seem to work both yours & Dave's solution probably would be safer.
 
That's interesting (and surprising to me).

Do you have xl97 to test, too? Just curious.
 
get feeling I've started something here!
I use 2003 and only with 2k versions I have applied (minor) dual coding
options along the lines I posted. Guess I got lucky!
 
Yes it was surprising to me too. As written it also works in XL97 subject
changing xlSortNormal to a number in the DataOption1 argument. Debug-Compile
even works with Option Explicit

There's an explanation and a catch - it only works like this:

With Selection
or
Dim objRange as Object 'OK
With objRange ' OK

but -
Dim rng as Range
With rng ' fails
or
With Range("A2:A10") ' fails

both fail with "named argument not found", DataOption1 highlit

Now it all makes sense !

Regards,
Peter T
 
Yep - more luck than judgement - hope we have not confused Dale too much!
nice chating to you guys!
--
JB


Peter T said:
Yes it was surprising to me too. As written it also works in XL97 subject
changing xlSortNormal to a number in the DataOption1 argument. Debug-Compile
even works with Option Explicit

There's an explanation and a catch - it only works like this:

With Selection
or
Dim objRange as Object 'OK
With objRange ' OK

but -
Dim rng as Range
With rng ' fails
or
With Range("A2:A10") ' fails

both fail with "named argument not found", DataOption1 highlit

Now it all makes sense !

Regards,
Peter T
 
Ah. Using kind of a "late binding" technique explains it.

Peter said:
Yes it was surprising to me too. As written it also works in XL97 subject
changing xlSortNormal to a number in the DataOption1 argument. Debug-Compile
even works with Option Explicit

There's an explanation and a catch - it only works like this:

With Selection
or
Dim objRange as Object 'OK
With objRange ' OK

but -
Dim rng as Range
With rng ' fails
or
With Range("A2:A10") ' fails

both fail with "named argument not found", DataOption1 highlit

Now it all makes sense !

Regards,
Peter T
 
You could excise most of these arguments anyway, since they merely tell
Excel to use the defaults.

- Jon
 
Personally, I like to specify all the parms (well, most the time <bg>).

There are some parms for some methods that are carried over from one command to
another--and even shared with the user (via the user interface)--like the .Find
method.

(Yeah, I'm not too careful when it comes to removing the dataoption stuff.)
 
Actually, whether luck or judgement, you have come up with something
potentially quite useful. Nice one!

Regards,
Peter T

john said:
Yep - more luck than judgement - hope we have not confused Dale too much!
nice chating to you guys!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top