Late binding issue - Microsoft.Office.Interop.Excel

Hi Experts

I am trying to build some custom code used for applying conditional formatting to a column in an Excel sheet. I am quite new to this though and I am having some issues with the late binding error “BC30574: Option Strict On disallows late binding”. The error applies for line 19, 23, 24, 25, 29, 31 and 40 in the simplified code snippet blow:

'Declare variables
Dim excelApp As Microsoft.Office.Interop.Excel.Application
Dim workBook As Microsoft.Office.Interop.Excel.Workbook
Dim workSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim oRange As Microsoft.Office.Interop.Excel.Range

'Setup new Excel session
excelApp = New Microsoft.Office.Interop.Excel.ApplicationClass

'Create new workbook
workBook = excelApp.Workbooks.Add

'Create worksheet object
workSheet = CType(workBook.Worksheets	(1), Microsoft.Office.Interop.Excel.Worksheet)

'Conditional formatting
oRange = workSheet.Range("A:A")
oRange.FormatConditions.AddIconSetCondition
oRange.FormatConditions(oRange.FormatConditions.Count).SetFirstPriority

With oRange.FormatConditions(1)
	
	.ReverseOrder = False
	.ShowIconOnly = True
	.IconSet =workBook.IconSets(Microsoft.Office.Interop.Excel.XlIconSet.xl3Signs)
	
End With

oRange.FormatConditions(1).IconCriteria(1).Icon = Microsoft.Office.Interop.Excel.XlIcon.xlIconRedDiamond

With oRange.FormatConditions(1).IconCriteria(2)
	
	.Type = 0
	.Value = -0.2
	.Operator = 7
	.Icon = Microsoft.Office.Interop.Excel.XlIcon.xlIconGreenCircle
	
End With

With oRange.FormatConditions(1).IconCriteria(3)
	
	.Type = 0
	.Value = 0.2
	.Operator = 7
	.Icon = Microsoft.Office.Interop.Excel.XlIcon.xlIconYellowTriangle
	
End With

It seems to be issues with the .FormatConditions but I am not sure how to get around this.

Any idea?

1 Like