Invoke Code Activity - VB.net code Error - Option Strict On Disallows late binding

excel
studio
invoke_code

#1
  All, I am getting Invoke Code Activity  - VB.net code Error - Option Strict On Disallows late binding on below code  - but it runs on Visual Studio as ConsoleApplication 

Error Line = sheet_temp.Columns(“J”).ShowDetail = False
I tried to use sheet_temp.range().showdetail, but range class doesnt include showdetail function. Any idea to overcome Option Strict On Disallows late binding at Invoke code Activity.

Dim xlApp As Microsoft.Office.Interop.Excel.Application = Nothing
Dim xlWorkBooks As Microsoft.Office.Interop.Excel.Workbooks = Nothing
Dim wba As Microsoft.Office.Interop.Excel.Workbook = Nothing
Dim sheet_temp As Microsoft.Office.Interop.Excel.Worksheet = Nothing
Dim xlWorkSheets As Microsoft.Office.Interop.Excel.Sheets = Nothing
xlApp = New Microsoft.Office.Interop.Excel.Application
xlWorkSheets = wba.Sheets
sheet_temp = CType(xlWorkSheets(“Sheet0”), Microsoft.Office.Interop.Excel.Worksheet)
sheet_temp.Columns(“J”).ShowDetail = False


#2

UiPath doesn’t allow late binding. Read about the differences between early and late binding here https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/early-late-binding/


#3

Dave,

thanks for the link
if understand the concept of late binding, none of object variables shouldn’t work.
But above code sheet_temp.range(“J:J”).delete() works but sheet_temp.columns(“J:J”).delete() doesn’t work and throws the late binding error.

Thanks
Suresh


#4

I had a longer post written, but the gist of it is: What is this code trying to accomplish? Lots of dims at the beginning that appear unused, but maybe this is just a snippet.

An easy way to determine the late bound object is when you’re typing it out. If intellisense comes up, then early binding was used. If late binding is used, intellisense won’t work. When you type the last line sheet_temp. - does the intellisense pop up and show Columns? does .ShowDetail show up?

If you want, here’s an example of some code I’ve used to delete worksheets from a workbook. It should be easy enough to modify to your needs instead if you’d like. It uses TryCast rather than CType to get around the late binding issue when converting workbook.sheets object into a single workbook.sheet object. Note that filepath and sheetname are arguments passed in from the uipath workflow.

Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook

xlApp = New Microsoft.Office.Interop.Excel.Application
wb = xlApp.Workbooks.Open(filepath)

xlApp.DisplayAlerts = False
TryCast(wb.Sheets(sheetname), Microsoft.Office.Interop.Excel.Worksheet).Delete()
xlApp.DisplayAlerts = True

wb.Save()
wb.Close()

#5

Dave,

Thanks again.
yes intellisense works for sheet_temp.
image
image

i tried TryCast(wb.Sheets(sheet), Microsoft.Office.Interop.Excel.Worksheet).Columns(“J”).ShowDetail = False

This still has late binding error at Invoke code

But below code works
TryCast(wb.Sheets(sheet), Microsoft.Office.Interop.Excel.Worksheet).Range(“A:A”).EntireColumn.Hidden = False