Installation of program that uses Microsoft.Office.Interop

W

William LaMartin

I have created a program that allows for the automation of things in Word
documents, like changing the values of DocVariables and the links to Excel
Sheets. I did it using interoperoperatability, where, after adding a
reference to Microsoft.Office.Core and a reference to Microsoft Word I
declare objects as follows:

Dim oWordApp As New Microsoft.Office.Interop.Word.Application, .

Everything works fine on the development computer (Office 2003 is in use
here). But when I install the program on a computer running Windows ME
(Office 2002 in use here), the following happens.

1. The program opens fine. I am also able to start an instance of
Microsoft Word via the program, but when I attempt to open a specific
document with Word I get the error: "Object reference not set to an
instance of an object."


Dim docPath As New Object
Me.OpenFileDialog1.Filter = "Word files (*.doc)|*.doc"
If Me.OpenFileDialog1.ShowDialog() = DialogResult.OK Then
docPath = Me.OpenFileDialog1.FileName
End If
oWordApp.Visible = True
oWordApp.Documents.Open(docPath) 'Error occurs here


As a point of information, the following DLL's are installed in the
Application folder by the installation:

Interop. Microsoft.Office.Core.dll
Microsoft.Ofifice.Infterop.Excel.dll
Microsoft.Ofifice.Infterop.Word.dll
Microsoft.Vbe.Interop.dll
office.dll
stdole.dll

Is there a problem with using these DLLs above generated by Visual Studio?
I read this at Microsoft:

"You must also avoid the use of any Office XP COM interop assembly that is
generated by Microsoft Visual Studio .NET at design time. Any Office XP
interop assembly that is not included in the Office XP PIAs download is
considered unofficial."
 
K

Ken Tucker [MVP]

Hi,

You must either require the user have the same version of office
or use late binding.

Ken
----------------
I have created a program that allows for the automation of things in Word
documents, like changing the values of DocVariables and the links to Excel
Sheets. I did it using interoperoperatability, where, after adding a
reference to Microsoft.Office.Core and a reference to Microsoft Word I
declare objects as follows:

Dim oWordApp As New Microsoft.Office.Interop.Word.Application, .

Everything works fine on the development computer (Office 2003 is in use
here). But when I install the program on a computer running Windows ME
(Office 2002 in use here), the following happens.

1. The program opens fine. I am also able to start an instance of
Microsoft Word via the program, but when I attempt to open a specific
document with Word I get the error: "Object reference not set to an
instance of an object."


Dim docPath As New Object
Me.OpenFileDialog1.Filter = "Word files (*.doc)|*.doc"
If Me.OpenFileDialog1.ShowDialog() = DialogResult.OK Then
docPath = Me.OpenFileDialog1.FileName
End If
oWordApp.Visible = True
oWordApp.Documents.Open(docPath) 'Error occurs here


As a point of information, the following DLL's are installed in the
Application folder by the installation:

Interop. Microsoft.Office.Core.dll
Microsoft.Ofifice.Infterop.Excel.dll
Microsoft.Ofifice.Infterop.Word.dll
Microsoft.Vbe.Interop.dll
office.dll
stdole.dll

Is there a problem with using these DLLs above generated by Visual Studio?
I read this at Microsoft:

"You must also avoid the use of any Office XP COM interop assembly that is
generated by Microsoft Visual Studio .NET at design time. Any Office XP
interop assembly that is not included in the Office XP PIAs download is
considered unofficial."
 
W

William LaMartin

Thanks.

By adding Option Strict Off to the top of my code page and using the code
below, I can now create a VB.Net program that when installed on a computer
running a different version of Office than was installed on the development
computer (Office 2003), have it start Word and open a document.

Unfortunately when I create the Word object WordApp this way I loose the
intellisense for it. Is there a way to regain this for the object? Or must
I write the code using Microsoft.Office.Interop.Word.ApplicationClass so as
to have the iltellisense available for creating the code, and then remove
all instances of that and revert to the type of code below to actually use
it on other computers?

Dim WordApp As New Object
WordApp = CreateObject("Word.Application")
Dim docPath As String
Me.OpenFileDialog1.Filter = "Word files (*.doc)|*.doc"
If Me.OpenFileDialog1.ShowDialog() = DialogResult.OK Then
docPath = Me.OpenFileDialog1.FileName
End If
WordApp.Visible = True
WordApp.Documents.Open(docPath)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top