×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

MS Access 2013 late binding to Excel & WorkSheetFunction

MS Access 2013 late binding to Excel & WorkSheetFunction

MS Access 2013 late binding to Excel & WorkSheetFunction

(OP)
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

RE: MS Access 2013 late binding to Excel & WorkSheetFunction

Hi,

Try...

If objexcel_app.worksheetfunction.countif(xlsExcel_range, Cell.Value) > 1 Then

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: MS Access 2013 late binding to Excel & WorkSheetFunction

(OP)
Thanx Skip!

The code ran without failing

RE: MS Access 2013 late binding to Excel & WorkSheetFunction

👍

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: MS Access 2013 late binding to Excel & WorkSheetFunction

Just curios...

Wouldn't be beneficial (safer?) to have some:
With objexcel_app
...
End With

or
With xlsExcel_sheet
...
End With

around the code to fully qualify which property of which object we are 'messing' with?


---- Andy

There is a great need for a sarcasm font.

RE: MS Access 2013 late binding to Excel & WorkSheetFunction

I’d do it this way...

CODE

With xlsExcel_sheet
   Set xlsExcel_range = .Range("C5:C" & Z) 
   For Each Cell In xlsExcel_range
      With Cell
         If .Value = vbNullString Then
            .Borders(9).LineStyle = 4
            .Borders(8).LineStyle = 4
            .Borders(7).LineStyle = 4
            .Borders(10).LineStyle = 4
            .Borders(9).Color = RGB(255, 0, 0)
            .Borders(8).Color = RGB(255, 0, 0)
            .Borders(7).Color = RGB(255, 0, 0)
            .Borders(10).Color = RGB(255, 0, 0)

         Else

            If objexcel_app.worksheetfunction.countif(xlsExcel_range, Cell.Value) > 1 Then
               .Borders(9).LineStyle = 4
               .Borders(8).LineStyle = 4
               .Borders(7).LineStyle = 4
               .Borders(10).LineStyle = 4
               .Borders(9).Color = RGB(0, 0, 204)
               .Borders(8).Color = RGB(0, 0, 204)
               .Borders(7).Color = RGB(0, 0, 204)
               .Borders(10).Color = RGB(0, 0, 204)
            End If

         End If
      End With
   Next Cell
End With 

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: MS Access 2013 late binding to Excel & WorkSheetFunction

So Cell does not have to be defined? Or used with a period: .Cell ?

Always wonder if Option Explicit would allow some of the code to compile.
And I know from experience that Excel object (started from VB6) will allow not fully qualified code to run once, but the second time around complains about not fully qualified objects. But that may be just the VB's 'feature'... smile


---- Andy

There is a great need for a sarcasm font.

RE: MS Access 2013 late binding to Excel & WorkSheetFunction

Cell in his code, is IMPLICITLY a Variant data type. As a Variant, it can be used virtually as any kind of variable.

I would not have used “Cell” but in his code, Cell is an Each for the Object in the For...Next statement, and the Each for a Range object happens to be a cell with a implied reference to the Range object.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close