Jump to content

Excel Sort


Recommended Posts

Hello,

I need to do a sort with an excel file, listed below is the code I'mm using , I took this from a recorded macro in Excel. I made modfications to it

to reference the $Oexcel_to Variable that I'm using.

When I try and run this it fails on the line

$oExcel_to.ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key=Range("A:A"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

At the Add Key part of the string stating that their is a syntax error.

Any Ideas what I'm missing ?

#include <String.au3>

#include <Excel.au3>

#include <Array.au3>

#include <date.au3>

$oExcel_to=_ExcelBookOpen("c:\test1.xlsx",1)

$oExcel_to.Cells.Select

$oExcel_to.ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear

$oExcel_to.ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key=Range("A:A"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

With $oExcel_to.ActiveWorkbook.Worksheets("Sheet1").Sort

.SetRange Range("A:A")

.Header = xlYes

.MatchCase = False

.Orientation = xlTopToBottom

.SortMethod = xlPinYin

.Apply

End With

Edited by HighlanderSword
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...