I am trying to work with the Excel object without references to Excel (Late Binding). I am unable to get MS Access to recognize the excel function/method WorkSheetFunction in order to test for duplicates and make a simple background or border color change for the duplicates in a column/range. I was wondering if there is an alternative to WorkSheetFunction or if I am using it wrong
Here is the code. The Null value color change works just fine, it is when I attempt to use the WorkSheetfunction that the code fails:
Dim objexcel_app As Object
Dim xlsExcel_wkbook As Object
Dim xlsExcel_sheet As Object
Dim xlsExcel_range As Object
Dim Z As Long
Set objexcel_app = CreateObject("Excel.Application")
Set xlsExcel_wkbook = objexcel_app.Workbooks.Open("C:\Deal\New_NMTC_TLR_Note.xls")
Set xlsExcel_sheet = xlsExcel_wkbook.sheets("New_NMTC_TLR_Note")
Z = xlsExcel_sheet.UsedRange.rows(xlsExcel_sheet.UsedRange.rows.Count).row
Set xlsExcel_range = xlsExcel_sheet.Range("C5:C" & Z)
For Each Cell In xlsExcel_range
If Cell.Value = vbNullString Then
Cell.Borders(9).LineStyle = 4
Cell.Borders(8).LineStyle = 4
Cell.Borders(7).LineStyle = 4
Cell.Borders(10).LineStyle = 4
Cell.Borders(9).Color = RGB(255, 0, 0)
Cell.Borders(8).Color = RGB(255, 0, 0)
Cell.Borders(7).Color = RGB(255, 0, 0)
Cell.Borders(10).Color = RGB(255, 0, 0)
Else
If worksheetfunction.countif(xlsExcel_range, Cell) > 1 Then
Cell.Borders(9).LineStyle = 4
Cell.Borders(8).LineStyle = 4
Cell.Borders(7).LineStyle = 4
Cell.Borders(10).LineStyle = 4
Cell.Borders(9).Color = RGB(0, 0, 204)
Cell.Borders(8).Color = RGB(0, 0, 204)
Cell.Borders(7).Color = RGB(0, 0, 204)
Cell.Borders(10).Color = RGB(0, 0, 204)
End If
End If
Next Cell
Here is the code. The Null value color change works just fine, it is when I attempt to use the WorkSheetfunction that the code fails:
Dim objexcel_app As Object
Dim xlsExcel_wkbook As Object
Dim xlsExcel_sheet As Object
Dim xlsExcel_range As Object
Dim Z As Long
Set objexcel_app = CreateObject("Excel.Application")
Set xlsExcel_wkbook = objexcel_app.Workbooks.Open("C:\Deal\New_NMTC_TLR_Note.xls")
Set xlsExcel_sheet = xlsExcel_wkbook.sheets("New_NMTC_TLR_Note")
Z = xlsExcel_sheet.UsedRange.rows(xlsExcel_sheet.UsedRange.rows.Count).row
Set xlsExcel_range = xlsExcel_sheet.Range("C5:C" & Z)
For Each Cell In xlsExcel_range
If Cell.Value = vbNullString Then
Cell.Borders(9).LineStyle = 4
Cell.Borders(8).LineStyle = 4
Cell.Borders(7).LineStyle = 4
Cell.Borders(10).LineStyle = 4
Cell.Borders(9).Color = RGB(255, 0, 0)
Cell.Borders(8).Color = RGB(255, 0, 0)
Cell.Borders(7).Color = RGB(255, 0, 0)
Cell.Borders(10).Color = RGB(255, 0, 0)
Else
If worksheetfunction.countif(xlsExcel_range, Cell) > 1 Then
Cell.Borders(9).LineStyle = 4
Cell.Borders(8).LineStyle = 4
Cell.Borders(7).LineStyle = 4
Cell.Borders(10).LineStyle = 4
Cell.Borders(9).Color = RGB(0, 0, 204)
Cell.Borders(8).Color = RGB(0, 0, 204)
Cell.Borders(7).Color = RGB(0, 0, 204)
Cell.Borders(10).Color = RGB(0, 0, 204)
End If
End If
Next Cell