Using Invoke Method to code VBA .Net to sort column in Excel

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.Visible = True

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.XlYesNoGuess.xlNo, , , _
xlApp.XlSortOrientation.xlSortColumns, _
xlApp.XlSortMethod.xlStroke, _
xlApp.XlSortDataOption.xlSortNormal, _
xlApp.XlSortDataOption.xlSortNormal, _

I am getting an error that says

“No compiled code to run”


“error BC30574 Option Strict On disallows late binding at line xxxx”

several times.

Any suggestions would be greatly appreciated!

Hello @Bryan_Schmiedeler!

It seems that you have trouble getting an answer to your question in the first 24 hours.
Let us give you a few hints and helpful links.

First, make sure you browsed through our Forum FAQ Beginner’s Guide. It will teach you what should be included in your topic.

You can check out some of our resources directly, see below:

  1. Always search first. It is the best way to quickly find your answer. Check out the image icon for that.
    Clicking the options button will let you set more specific topic search filters, i.e. only the ones with a solution.

  2. Topic that contains most common solutions with example project files can be found here.

  3. Read our official documentation where you can find a lot of information and instructions about each of our products:

  4. Watch the videos on our official YouTube channel for more visual tutorials.

  5. Meet us and our users on our Community Slack and ask your question there.

Hopefully this will let you easily find the solution/information you need. Once you have it, we would be happy if you could share your findings here and mark it as a solution. This will help other users find it in the future.

Thank you for helping us build our UiPath Community!

Cheers from your friendly


  • firstly. “” not existing languages . There are “” and “vba” languages .it’s different languages .

  • If i’am solving task like this , i’m prefer using vba and “invoke vba” activity. it’s just relative to use “” for excel .

  • and “yes” you must to use early binding when you try use for excel