First you need to add the Microsoft Excel Objects Library to your references.
This is found Under the Projects Menu, References Item.
Code:
Private Function ExcelSortActiveSheet() As Boolean
On Error GoTo Done
Dim xlApp As Excel.Application
Dim xlSheet As Excel.Worksheet
' Create new hidden instance of Excel.
Set xlApp = New Excel.Application
' Show this instance of Excel during tests.
'xlApp.Visible = True 'uncomment to make excel visable
'open excel file
xlApp.Workbooks.Open "c:\Excel Projects\test.xls"
'get active sheet
Set xlSheet = xlApp.ActiveSheet
'apply your sort
xlSheet.Cells.Sort Key1:=Range("A1")
'close the workbook and save the changes
xlApp.ActiveWorkbook.Close True
Done:
On Error Resume Next
'End the excel application
xlApp.Quit
'Don't forget to free up memory and resources
Set xlSheet = Nothing
Set xlApp = Nothing
End Function
Bookmarks