INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

COM and Automation

Excel Automation Sort by jmcd0719
Posted: 13 Feb 04

*The documentation on sorting a table in Excel is lacking
*The syntax for using the sort object is as follows

public oleapp
oleapp=Createobject("excel.application")

*There are 12 parameters:
lkey1='oleapp.Range("a1")'  && Column you want to sort
lorder1=1   && 1 - Ascending 2 - Decending (default 1)
ltype=""   && Leave Blank (default blank)
lkey2='oleapp.Range("b1")' && Second Column (default blank)
lorder2=1  && same as above (default 1)
lkey3='oleapp.Range("c1")' && Third Column (default blank)
lorder3=1  && same as above (default 1)
lheader=1  && Does table have Header 0-Guess,1-Yes,2-No (Default 0)
&&lcustom= skip altogher
lmatch=.f. && match case .t.=Yes .f.=NO (default .f.)
&&lorient= Skip altogether
lsortmeth=1  && not sure if used (default 1)
ldataopt1=0  && Sort normally, by month, day, etc (default 0)
ldataopt2=0  && Same as opt1
ldataopt3=0  && Same as opt2

oleapp.Visible=.T.
l_file="c:\test.csv"  && any file will do that opens natively in excel"
oleapp.Workbooks.Open(l_file)
lrange="a2:iv65536"
oleapp.Range(lrange).Sort(&lkey1)  && Simplest sort using defaults
&& sorting using variables
oleapp.Range(lrange).Sort(&lkey1,lorder1,ltype,&lkey2,lorder2,&lkey3,lorder3,lheader,,lmatch,,lsortmeth,ldataopt1,ldataopt2,ldataopt3)
&& sorting with values
oleapp.Range("a2:iv65536").Sort(oleapp.Range("a1"),1,,oleapp.Range("b1"),1,oleapp.Range("c1"),1,1,,.f.,,1,0,0,0)



Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close