The Sort Macro does not work in my new application Calc 7.5

The following is my macro which I have attached to a push button control but it does not work. I have tried everything I can think of. Does anybody have any idea where I am going wrong.
Thanks,
OldJack

Sub Sort_Restore
Dim oSheet
Dim oRange
Dim oSortFields(0) as new com.sun.star.util.SortField
Dim oSortDesc(0) as new com.sun.star.beans.PropertyValue
oSheet = ThisComponent.Sheets(0)
oRange = oSheet.getCellRangeByName(“B10:M269”)
oSortFields(0).Field = 1
oSortFields(0).SortAscending = True
oSortDesc(0).Name = “SortFields”
oSortDesc(0).Value = oSortFields()
oRange.Sort(oSortDesc())
End Sub

You didn’t append your file, so

  • we can not see, if you saved as xlsx, preventing macros to run
  • we can not check, if your button is linked to the proper subroutine
  • we can not see, if sheets(0) is correct

but maybe your error is in the code you posted…

The Macro when executed by the Basic IDE, works. If YES, the problem is in the button, replace it with an image/picture.


If possible post an example of the file.

Thanks for the reply. Unfortunately the macro does not run in the IDE.

Thank you for your reply. I’m an old guy and sometimes make stupid mistakes. I found the problem and it is a little embarrassing but I simply had the wrong sheet index.

JT

1 Like

Change macro to worksheet name, avoid error, if change worksheet position


in
oSheet = ThisComponent.Sheets(0)


for
oSheet = ThisComponent.getSheets.getByName( "SheetName" )

Thankyou

1 Like