Srinivas
Srinivas

Reputation: 171

MS Office 14.0 object library references in VB 6 program

My VB 6 program code is referring to 14.0 object library, it is compiled and executed..working fine with the new code (accessing 14.0 libraries).

In my development system, Microsoft Office 2010 is installed (14.0 library), where my new code is compiled and working fine..

I'm using these libraries to convert document to pdf.

I'm trying to install the setup of the same VB 6 program and run in different machine, where 14.0 libraries are not present, because MS Office 2000 is installed on that machine (12.0 libraries).

Setup installation is getting successful, but the program is throwing an error while referencing 14.0 libraries.

Now, I need a help in this regard, that, How can I install the 14.0 object libraries on the new machine, so that the references will be there for the program to run.

Or, please suggest me any other approaches to get it done..

Thanks

Upvotes: 2

Views: 17063

Answers (1)

Siddharth Rout
Siddharth Rout

Reputation: 149305

The problem is that you are using Early Binding. You have to use Late Binding.

In Early Binding, you set a reference to the Excel Object xx.xx Library where as in late Binding you do not.

Here is an example of both

Early Binding

Sub EarlyBindingEx()
    Dim oXLApp As Excel.Application
    Dim oXLWb As Excel.Workbook
    Dim oXLWs As Excel.Worksheet

    '~~> Establish an EXCEL application object
    On Error Resume Next
    Set oXLApp = GetObject(, "Excel.Application")

    '~~> If not found then create new instance
    If Err.Number <> 0 Then
        Set oXLApp = New Excel.Application
    End If
    Err.Clear
    On Error GoTo 0

    '~~> Show Excel
    oXLApp.Visible = True

    '~~> Open files
    Set oXLWb = oXLApp.Workbooks.Open("C:\Sample.xlsx")

    '~~> Set the relevant worksheet
    Set oXLWs = oXLWb.Sheets(1)

    '
    '~~> Rest of your code
    '
End Sub

Late Binding

Sub LateBindingEx()
    Dim oXLApp As Object
    Dim oXLWb As Object, oXLWs As Object

    '~~> Establish an EXCEL application object
    On Error Resume Next
    Set oXLApp = GetObject(, "Excel.Application")

    '~~> If not found then create new instance
    If Err.Number <> 0 Then
        Set oXLApp = CreateObject("Excel.Application")
    End If
    Err.Clear
    On Error GoTo 0

    '~~> Show Excel
    oXLApp.Visible = True

    '~~> Open files
    Set oXLWb = oXLApp.Workbooks.Open("C:\Sample.xlsx")

    '~~> Set the relevant worksheet
    Set oXLWs = oXLWb.Sheets(1)

    '
    '~~> Rest of your code
    '
End Sub

HERE is an MSDN link regarding Early Binding Vs Late Binding.

Upvotes: 10

Related Questions