What is 'late binding'?

cheoksoon

Board Regular
Joined
Aug 25, 2016
Messages
56
Hi everybody,

I'm still trying to wrap my head around the idea of 'early' and 'late' binding and I couldn't understand it. I've looked up on google but I don't know how to apply to my code.

Basically, I started looking for solutions when I created a shared file but people using different versions of excel. Some people has Microsoft Office 15.0 Object Library while others have Microsoft Office 16.0 Object library. A 'compiling error' often occurs for some when trying to run the program.

I heard 'late binding' can resolve the situation but I don't know how to apply it to my code:

My code is something like this:
Code:
Dim sheet1 As Worksheet
    Set sheet1 = Sheets("Data")
    Dim sheet2 As Worksheet
    Set sheet2 = Sheets("Stats")
    
    Dim i As Integer
    Dim j As Integer
    Dim k As Integer
    Dim l As Integer
    
    Dim start_row As Integer
    Dim end_row As Integer
    Dim start_col As Integer
    Dim end_col As Integer
    
    start_row = 2       
    end_row = 46       
    start_col = 10      
    end_col = 37       
    start_col_CE = 39 
    end_col_CE = 45  
    
    For i = start_row To end_row
        For j = start_col To end_col Step 4
            If sheet1.Cells(i, j) <> "" And sheet1.Cells(i, j) < sheet1.Range("A48") Then
            
                'some function here


                If sheet1.Cells(i, 46) <> 0 Then
                    For k = start_col_CE To end_col_CE
                        If sheet1.Cells(i, k) = "" Then
                            empty_col_CE = k
                            Exit For
                        End If
                    Next k
                    
                    CE_date = CDate(sheet1.Cells(i, j))
                    CE_month = Month(CE_date)
                    CE_month_row = CE_month + 1
                    
                    'some function here
                    
                    sheet2.Cells(CE_month_row, CE_type_col) = sheet2.Cells(CE_month_row, CE_type_col) + 1
                    
                    sheet1.Cells(i, empty_col_CE) = CE_type & CE_date & " : " & sheet1.Cells(i, j + 2)
                    sheet1.Range(Cells(i, j), Cells(i, j + 3)) = ""
                    
                
                ElseIf sheet1.Cells(i, 46) = 0 Then
                    For l = start_col_CE To end_col_CE - 1
                        sheet1.Cells(i, l) = sheet1.Cells(i, l + 1)
                    Next l
                    
                    CE_date = CDate(sheet1.Cells(i, j))
                    CE_month = Month(CE_date)
                    CE_month_row = CE_month + 1
                    
                   'Some function here
                    
                    sheet2.Cells(CE_month_row, CE_type_col) = sheet2.Cells(CE_month_row, CE_type_col) + 1
                    
                    sheet1.Cells(i, end_col_CE) = CE_type & CE_date & " : " & sheet1.Cells(i, j + 2)
                    sheet1.Range(Cells(i, j), Cells(i, j + 3)) = ""
                
                End If
            End If
        Next j
    Next i

How do apply late binding to my code?
 
Last edited:

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Late binding is only really used when you are automating another application, e.g. Word, from Excel.

You aren't going that in the posted code so I don't think late binding will help.

What errors are you getting?
 
Upvote 0
Late binding is only really used when you are automating another application, e.g. Word, from Excel.

You aren't going that in the posted code so I don't think late binding will help.

What errors are you getting?

Oh really? Oops... that's the problem with google searching.

I'm getting the error " compile error: can't find project or library".

I clicked on tools -> Reference to find the 'missing' object library. It says Missing: microsoft office 16.0 object library. This error doesn't occur for those of my colleagues who has 16.0 object library but a lot of my other colleages only has 15.0 object library.

I can't update or reinstall the version of excel because I don't have the appropriate permissions to do so.

How do I get around this?
 
Upvote 0
Just remove the reference & see what happens.
As Norie said there is no need for it with the code you posted, but it maybe needed for another macro.
 
Upvote 0
Just remove the reference & see what happens.
As Norie said there is no need for it with the code you posted, but it maybe needed for another macro.

Sorry, I removed all the references but the problem still exists. :(
 
Last edited:
Upvote 0
Oh wait...

I solved the problem.

Turns out I have to declare each and every variable (i.e. Dim) which I didn't do. Now that I did, everything seemed ok now...

Thanks everybody!
 
Upvote 0
Glad you solved it & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,126
Members
452,381
Latest member
Nova88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top