Jump to content

Excel macro to autoit code


Recommended Posts

Columns("A:M").Select
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("M2:M809") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").Sort
        .SetRange Range("A1:M809")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With

Hi,

 

I can't get this vba code that I got from an excel macro to work with autoit.

Link to comment
Share on other sites

Please have a look at the latest AutoIt beta version (3.3.11.4). it comes with a sort function (_Excel_RangeSort) that should do what you need.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thank you for the kind welcome.

I need to automate some actions on an excel file outside of excel.

So I came across autoit :bye:

Everything seems to be kind of straight foreward but I was struggeling to transform that := property notation to something that is accepted by autoit.

I need to keep the header of a file and sort all other rows based on column M.

This is what I had so far (part of it is commented out )

  • treating the := as a property
  • treating the whole thing as a single string
  • with or without ()
$exlYes=1
$exlTopToBottom=1
$exlPinYin=1
$exlSortOnValues=0
$exlAscending=1
$exlSortNormal=0
$exlSortColumns=1

;$oExcel1.ActiveSheet.Columns("A:M").Select
;$oExcel1.ActiveSheet.Sort.SortFields.Clear
;$oExcel1.ActiveSheet.Sort.SortFields.Add('Key:=Range("M2:M"' & $iLastLineNr & '), SortOn:=' & $xlSortOnValues & ', Order:=' & $xlAscending & ', DataOption:=' & $xlSortNormal)
;$oExcel1.ActiveSheet.Sort.SetRange($oExcel1.ActiveSheet.Range("A1:M" & $iLastLineNr))
;$oExcel1.ActiveSheet.Sort.Header = $exlYes
;$oExcel1.ActiveSheet.Sort.MatchCase = False
;$oExcel1.ActiveSheet.Sort.Orientation = $exlTopToBottom
;$oExcel1.ActiveSheet.Sort.SortMethod = $exlPinYin
;$oExcel1.ActiveSheet.Sort.Apply

Though I finally managed to get it working by extending a piece of code I found via google and figuring out how to put in the unused properties in the function.

It has a totally different approach, but the end result is the same.

$oExcel1.ActiveSheet.Range("M1").Sort($oExcel1.ActiveSheet.Range("M:M"), $exlAscending, Null, Null, $exlAscending, Null, $exlAscending, $exlYes, Null, False, $exlSortColumns, $exlPinYin, $exlSortNormal, $exlSortNormal, $exlSortNormal)

I wasn't aware of the _Excel_RangeSort function.

Though I still would like to know what the autoit alternative is for the vba := notation.

Link to comment
Share on other sites

Though I still would like to know what the autoit alternative is for the vba := notation.

AutoIt doesn't support named parameters.

"Key" is the first parameter in the parameter list. So simply drop the "Key:=" part and only add the value of the parameter e.g. Range("M2:M809")

Replace parameters you don't know with the "Default" keyword.

Details can be found here.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...