Vpp Man
Vpp Man

Reputation: 2546

Reference issue in VB.net

In my program I use Microsoft Word 12.0 Object Library to automate Word and my system has Office2007 installed. If i pack this project and gives to my customer, it causes any problem?

My customer's computer should have Office 2007 installed in it for working of my program? What happens if he has only Office2003? If any problems is caused what is correct method to solve it or dynamically change the reference back to 11.0 Object Library?

When I checked "My Reference" from Project properties window, it lists three references:

Microsoft Office 12.0 Object Library --> vpp\obj\x86\Debug\Interop.Microsoft.Office.Core.dll
Microsoft Visual Basic for Applications Extensibility 5.3 --> vpp\obj\x86\Debug\Interop.VBIDE.dll
Microsoft Word 12.0 Object Library --> vpp\obj\x86\Debug\Interop.Microsoft.Office.Interop.Word.dll

These three dlls are in my debug folder. So it will work in my customer's computer?

Upvotes: 0

Views: 3370

Answers (1)

Michał Powaga
Michał Powaga

Reputation: 23183

If you are using early binding you may get error described in The Microsoft.Office.Interop.Word assembly version is higher than referenced (it's C# example but in VB it's going to look similar).

About differences between late binding and early binding you can read in Binding for Office automation servers with Visual C# .NET (still C# eaxamples) and Using early binding and late binding in Automation describes how to do it in VB.

Code might look like this (example from VBA – Word – Open Word using Late Binding):

Sub LaunchWord()
Dim objApp As Object

    'See if Word is already running
    On Error Resume Next
    Set objApp = GetObject(, "Word.Application")

    If Err.Number <> 0 Then
        'Launch a new instance of Word
        Err.Clear
        On Error GoTo Error_Handler
        Set objApp = CreateObject("Word.Application")
        objApp.Visible = True 'Make the application visible to the user (if wanted)
    End If

Exit Sub

Error_Handler:
    MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf & "Error Number: " & _
    Err.Number & vbCrLf & "Error Source: LaunchWord" & vbCrLf & "Error Description: " & _
    Err.Description, vbCritical, "An Error has Occured!"
    Exit Sub
End Sub

Added:

"Late binding" means "no intellisense", so have look at Take advantage of Intellisense when writing late bound code.

Upvotes: 1

Related Questions