Surprised that there is no Excel activity to sort a column in Excel.
You can do it by reading a range into a DataTable, sorting that and then moving data back, but that seems somewhat convoluted.
Would like to take advantage of Invoke Code to just write some VBA .NET to do this. Advantage would be could get experience using VBA .NET and invoke code. Then package this and other utilities into package so we could do lots of excel and file manipulation.
I know some VBA and .NET, but am not an expert.
Here is the code that I have written so far:
\ Dim xlApp As Microsoft.Office.Interop.Excel._Application = Nothing
Dim xlWorkBooks As Microsoft.Office.Interop.Excel.Workbooks=Nothing
Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook=Nothing
Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet=Nothing
Dim xlWorkSheets As Microsoft.Office.Interop.Excel.Sheets=Nothing
Dim xlRange As Microsoft.Office.Interop.Excel.Range=Nothing
Dim sortRange As Microsoft.Office.Interop.Excel.Range=Nothing
Dim myRange As Microsoft.Office.Interop.Excel.Range=Nothing
Dim namedRange1 As Microsoft.Office.Interop.Excel.Range=Nothing
Dim oSheet As Microsoft.Office.Interop.Excel.Worksheet=Nothing
xlApp=New Microsoft.Office.Interop.Excel.ApplicationClass
xlApp.DisplayAlerts=False
xlWorkBooks=xlApp.Workbooks
xlWorkBook=xlWorkBooks.Open(“C:\Users\BSchmiedeler\Desktop\Test.xlsx”)
xlApp.Visible = True
xlWorkSheets=xlWorkBook.Sheets
xlWorkSheet= CType(xlWorkSheets(1),Microsoft.Office.Interop.Excel.Worksheet)
oSheet = CType(xlWorkSheets(1),Microsoft.Office.Interop.Excel.Worksheet)
oSheet.Columns.Sort(oSheet.Range(“A3”, “A10”), _
xlApp.XlSortOrder.xlAscending, , , _
xlApp.XlSortOrder.xlAscending, , _
xlApp.XlSortOrder.xlAscending,
xlApp.XlYesNoGuess.xlNo, , , _
xlApp.XlSortOrientation.xlSortColumns, _
xlApp.XlSortMethod.xlStroke, _
xlApp.XlSortDataOption.xlSortNormal, _
xlApp.XlSortDataOption.xlSortNormal, _
xlApp.XlSortDataOption.xlSortNormal)
I am getting an error that says
“No compiled code to run”
and
“error BC30574 Option Strict On disallows late binding at line xxxx”
several times.
Any suggestions would be greatly appreciated!