Problem with Word...

  • Thread starter Thread starter Simon Verona
  • Start date Start date
S

Simon Verona

I have a problem with automating MS Word through vb.net

My code is :

Dim objword As new Word.ApplicationClass
Try
objWord.Documents.Open(letterfile)
objWord.Documents.Item(letterfile).Activate()
Catch
MsgBox("Error - Word Not running properly - letterfile=" & letterfile &
vbCrLf & " Error = " & Err.Description)
openletter = True
Exit Function
End Try

This works fine on my development machine with Word XP installed. However,
when installed on another PC (with Word 2000 installed) it fails with an
error "Object reference not set to an instance of an object". I can tell
from the task manager that Word has started up and is running but beyond
that I can't work out what the problem is. I have distributed the
application simply by using the Windows installer project which seems to
distribute an interop.word library.

I don't know what else to try.... I'm presuming that as I have Word XP on
my development machine that any word code should be backwardly compatible.

Any thoughts?

Regards
Simon
 
First question is if all the versions of office are the same ?. if not it
may be that the class hierarchy has changed between the two.


Regards - OHM
 
No, the versions of office are different...

However, this is a port of code that worked fine on vb6! I suspect
therefore that the office stuff should work the same...

Regards
Simon
 
Hi Simon,

This may seem like a really "Dumb" question, so if it is please forgive me,
but does letterfile actually exists in the path you are looking for it in
the system which does not work ?, I presume it fails in the Try section
because the objWord . . .Activate?

Regards - OHM
 
yes, the letterfile does actually exist (I thought that this was the problem
myself)... It's the same letterfile on both my development machine (on which
it works) and the other PC (which it doesn't) ... The document in question
is on a networked drive so it is *exactly* the same document.

You can open the document manually from either machine...

Regards
Simon
 
One last thought !

Does your document reference use UNC pathnames IE (
\\SERVER\RESOURCE\DOCUMENTNAME ). If this is the case then maybe your
version of word running on Win2K does not support this from a code point of
view ( although I doubt it ).

One alternative may be to put the letterfile on the users hard disk and
change the path to a local direcectory\filename. At least this would rule
this out.

Regards - OHM


Simon said:
yes, the letterfile does actually exist (I thought that this was the
problem myself)... It's the same letterfile on both my development
machine (on which it works) and the other PC (which it doesn't) ...
The document in question is on a networked drive so it is *exactly*
the same document.

You can open the document manually from either machine...

Regards
Simon

One Handed Man said:
Hi Simon,

This may seem like a really "Dumb" question, so if it is please
forgive me, but does letterfile actually exists in the path you are
looking for it in the system which does not work ?, I presume it
fails in the Try section because the objWord . . .Activate?

Regards - OHM


Simon said:
No, the versions of office are different...

However, this is a port of code that worked fine on vb6! I suspect
therefore that the office stuff should work the same...

Regards
Simon
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in
message First question is if all the versions of office are the same ?. if
not it may be that the class hierarchy has changed between the two.


Regards - OHM


Simon Verona wrote:
I have a problem with automating MS Word through vb.net

My code is :

Dim objword As new Word.ApplicationClass
Try
objWord.Documents.Open(letterfile)
objWord.Documents.Item(letterfile).Activate()
Catch
MsgBox("Error - Word Not running properly - letterfile=" &
letterfile & vbCrLf & " Error = " & Err.Description)
openletter = True
Exit Function
End Try

This works fine on my development machine with Word XP installed.
However, when installed on another PC (with Word 2000 installed)
it fails with an error "Object reference not set to an instance
of an object". I can tell from the task manager that Word has
started up and is running but beyond that I can't work out what
the problem is. I have distributed the application simply by
using the Windows installer project which seems to distribute an
interop.word library.

I don't know what else to try.... I'm presuming that as I have
Word XP on my development machine that any word code should be
backwardly compatible.

Any thoughts?

Regards
Simon
 
Tried that.. the document was originally on a mapped network drive, but I
copied it local.

I'm running out of options now!!

I'm just hoping that somebody has some inspiration for me!!!

I'm presuming that I don't have to do something special with the install
scripts to distribute/use the correct version of the Word Objects??

Regards
Simon
One Handed Man said:
One last thought !

Does your document reference use UNC pathnames IE (
\\SERVER\RESOURCE\DOCUMENTNAME ). If this is the case then maybe your
version of word running on Win2K does not support this from a code point of
view ( although I doubt it ).

One alternative may be to put the letterfile on the users hard disk and
change the path to a local direcectory\filename. At least this would rule
this out.

Regards - OHM


Simon said:
yes, the letterfile does actually exist (I thought that this was the
problem myself)... It's the same letterfile on both my development
machine (on which it works) and the other PC (which it doesn't) ...
The document in question is on a networked drive so it is *exactly*
the same document.

You can open the document manually from either machine...

Regards
Simon

One Handed Man said:
Hi Simon,

This may seem like a really "Dumb" question, so if it is please
forgive me, but does letterfile actually exists in the path you are
looking for it in the system which does not work ?, I presume it
fails in the Try section because the objWord . . .Activate?

Regards - OHM


Simon Verona wrote:
No, the versions of office are different...

However, this is a port of code that worked fine on vb6! I suspect
therefore that the office stuff should work the same...

Regards
Simon
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in
message First question is if all the versions of office are the same ?. if
not it may be that the class hierarchy has changed between the two.


Regards - OHM


Simon Verona wrote:
I have a problem with automating MS Word through vb.net

My code is :

Dim objword As new Word.ApplicationClass
Try
objWord.Documents.Open(letterfile)
objWord.Documents.Item(letterfile).Activate()
Catch
MsgBox("Error - Word Not running properly - letterfile=" &
letterfile & vbCrLf & " Error = " & Err.Description)
openletter = True
Exit Function
End Try

This works fine on my development machine with Word XP installed.
However, when installed on another PC (with Word 2000 installed)
it fails with an error "Object reference not set to an instance
of an object". I can tell from the task manager that Word has
started up and is running but beyond that I can't work out what
the problem is. I have distributed the application simply by
using the Windows installer project which seems to distribute an
interop.word library.

I don't know what else to try.... I'm presuming that as I have
Word XP on my development machine that any word code should be
backwardly compatible.

Any thoughts?

Regards
Simon
 
Simon,

Good point, can you establish if the Msoffice DLL you need is on the target
? I'm sorry but I have to leave now, let me know how you get on.

Regards - OHM




Simon said:
Tried that.. the document was originally on a mapped network drive,
but I copied it local.

I'm running out of options now!!

I'm just hoping that somebody has some inspiration for me!!!

I'm presuming that I don't have to do something special with the
install scripts to distribute/use the correct version of the Word
Objects??

Regards
Simon
One Handed Man said:
One last thought !

Does your document reference use UNC pathnames IE (
\\SERVER\RESOURCE\DOCUMENTNAME ). If this is the case then maybe
your version of word running on Win2K does not support this from a
code point of view ( although I doubt it ).

One alternative may be to put the letterfile on the users hard disk
and change the path to a local direcectory\filename. At least this
would rule this out.

Regards - OHM


Simon said:
yes, the letterfile does actually exist (I thought that this was the
problem myself)... It's the same letterfile on both my development
machine (on which it works) and the other PC (which it doesn't) ...
The document in question is on a networked drive so it is *exactly*
the same document.

You can open the document manually from either machine...

Regards
Simon

"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in
message Hi Simon,

This may seem like a really "Dumb" question, so if it is please
forgive me, but does letterfile actually exists in the path you are
looking for it in the system which does not work ?, I presume it
fails in the Try section because the objWord . . .Activate?

Regards - OHM


Simon Verona wrote:
No, the versions of office are different...

However, this is a port of code that worked fine on vb6! I
suspect therefore that the office stuff should work the same...

Regards
Simon
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in
message First question is if all the versions of office are the same ?.
if not it may be that the class hierarchy has changed between
the two.


Regards - OHM


Simon Verona wrote:
I have a problem with automating MS Word through vb.net

My code is :

Dim objword As new Word.ApplicationClass
Try
objWord.Documents.Open(letterfile)
objWord.Documents.Item(letterfile).Activate()
Catch
MsgBox("Error - Word Not running properly - letterfile=" &
letterfile & vbCrLf & " Error = " & Err.Description)
openletter = True
Exit Function
End Try

This works fine on my development machine with Word XP
installed. However, when installed on another PC (with Word
2000 installed) it fails with an error "Object reference not
set to an instance of an object". I can tell from the task
manager that Word has started up and is running but beyond that
I can't work out what the problem is. I have distributed the
application simply by using the Windows installer project which
seems to distribute an interop.word library.

I don't know what else to try.... I'm presuming that as I have
Word XP on my development machine that any word code should be
backwardly compatible.

Any thoughts?

Regards
Simon
 
It certainly *appears* to be...

If I add the line objword.visible=true after the dim objword.. line then
I see Word appear on screen... This *suggests* that I have some sort of link
to the correct dll's!!! It just seems to refuse to open a document!!

I can even do things like msgbox(objword.version) which shows the correct
version of word on each of the PC's (v10.0 on the development machine, v9.0
on the client).

Regards
Simon


One Handed Man said:
Simon,

Good point, can you establish if the Msoffice DLL you need is on the target
? I'm sorry but I have to leave now, let me know how you get on.

Regards - OHM




Simon said:
Tried that.. the document was originally on a mapped network drive,
but I copied it local.

I'm running out of options now!!

I'm just hoping that somebody has some inspiration for me!!!

I'm presuming that I don't have to do something special with the
install scripts to distribute/use the correct version of the Word
Objects??

Regards
Simon
One Handed Man said:
One last thought !

Does your document reference use UNC pathnames IE (
\\SERVER\RESOURCE\DOCUMENTNAME ). If this is the case then maybe
your version of word running on Win2K does not support this from a
code point of view ( although I doubt it ).

One alternative may be to put the letterfile on the users hard disk
and change the path to a local direcectory\filename. At least this
would rule this out.

Regards - OHM


Simon Verona wrote:
yes, the letterfile does actually exist (I thought that this was the
problem myself)... It's the same letterfile on both my development
machine (on which it works) and the other PC (which it doesn't) ...
The document in question is on a networked drive so it is *exactly*
the same document.

You can open the document manually from either machine...

Regards
Simon

"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in
message Hi Simon,

This may seem like a really "Dumb" question, so if it is please
forgive me, but does letterfile actually exists in the path you are
looking for it in the system which does not work ?, I presume it
fails in the Try section because the objWord . . .Activate?

Regards - OHM


Simon Verona wrote:
No, the versions of office are different...

However, this is a port of code that worked fine on vb6! I
suspect therefore that the office stuff should work the same...

Regards
Simon
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in
message First question is if all the versions of office are the same ?.
if not it may be that the class hierarchy has changed between
the two.


Regards - OHM


Simon Verona wrote:
I have a problem with automating MS Word through vb.net

My code is :

Dim objword As new Word.ApplicationClass
Try
objWord.Documents.Open(letterfile)
objWord.Documents.Item(letterfile).Activate()
Catch
MsgBox("Error - Word Not running properly - letterfile=" &
letterfile & vbCrLf & " Error = " & Err.Description)
openletter = True
Exit Function
End Try

This works fine on my development machine with Word XP
installed. However, when installed on another PC (with Word
2000 installed) it fails with an error "Object reference not
set to an instance of an object". I can tell from the task
manager that Word has started up and is running but beyond that
I can't work out what the problem is. I have distributed the
application simply by using the Windows installer project which
seems to distribute an interop.word library.

I don't know what else to try.... I'm presuming that as I have
Word XP on my development machine that any word code should be
backwardly compatible.

Any thoughts?

Regards
Simon
 
Then is it the document itself which is trying to access a resource which
does not exist onthe target ?

OHM

Simon said:
It certainly *appears* to be...

If I add the line objword.visible=true after the dim objword..
line then I see Word appear on screen... This *suggests* that I have
some sort of link to the correct dll's!!! It just seems to refuse to
open a document!!

I can even do things like msgbox(objword.version) which shows the
correct version of word on each of the PC's (v10.0 on the development
machine, v9.0 on the client).

Regards
Simon


One Handed Man said:
Simon,

Good point, can you establish if the Msoffice DLL you need is on the
target ? I'm sorry but I have to leave now, let me know how you get
on.

Regards - OHM




Simon said:
Tried that.. the document was originally on a mapped network drive,
but I copied it local.

I'm running out of options now!!

I'm just hoping that somebody has some inspiration for me!!!

I'm presuming that I don't have to do something special with the
install scripts to distribute/use the correct version of the Word
Objects??

Regards
Simon
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in
message One last thought !

Does your document reference use UNC pathnames IE (
\\SERVER\RESOURCE\DOCUMENTNAME ). If this is the case then maybe
your version of word running on Win2K does not support this from a
code point of view ( although I doubt it ).

One alternative may be to put the letterfile on the users hard disk
and change the path to a local direcectory\filename. At least this
would rule this out.

Regards - OHM


Simon Verona wrote:
yes, the letterfile does actually exist (I thought that this was
the problem myself)... It's the same letterfile on both my
development machine (on which it works) and the other PC (which
it doesn't) ... The document in question is on a networked drive
so it is *exactly* the same document.

You can open the document manually from either machine...

Regards
Simon

"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in
message Hi Simon,

This may seem like a really "Dumb" question, so if it is please
forgive me, but does letterfile actually exists in the path you
are looking for it in the system which does not work ?, I
presume it fails in the Try section because the objWord . .
.Activate?

Regards - OHM


Simon Verona wrote:
No, the versions of office are different...

However, this is a port of code that worked fine on vb6! I
suspect therefore that the office stuff should work the same...

Regards
Simon
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in
message First question is if all the versions of office are the same ?.
if not it may be that the class hierarchy has changed between
the two.


Regards - OHM


Simon Verona wrote:
I have a problem with automating MS Word through vb.net

My code is :

Dim objword As new Word.ApplicationClass
Try
objWord.Documents.Open(letterfile)
objWord.Documents.Item(letterfile).Activate()
Catch
MsgBox("Error - Word Not running properly - letterfile=" &
letterfile & vbCrLf & " Error = " & Err.Description)
openletter = True
Exit Function
End Try

This works fine on my development machine with Word XP
installed. However, when installed on another PC (with Word
2000 installed) it fails with an error "Object reference not
set to an instance of an object". I can tell from the task
manager that Word has started up and is running but beyond
that I can't work out what the problem is. I have distributed
the application simply by using the Windows installer project
which seems to distribute an interop.word library.

I don't know what else to try.... I'm presuming that as I
have Word XP on my development machine that any word code
should be backwardly compatible.

Any thoughts?

Regards
Simon
 
I'll try other documents.... the document is pretty much self contained,
and opens in Word on it's own...

It's mystifying me !!!

Regards
Simon
One Handed Man said:
Then is it the document itself which is trying to access a resource which
does not exist onthe target ?

OHM

Simon said:
It certainly *appears* to be...

If I add the line objword.visible=true after the dim objword..
line then I see Word appear on screen... This *suggests* that I have
some sort of link to the correct dll's!!! It just seems to refuse to
open a document!!

I can even do things like msgbox(objword.version) which shows the
correct version of word on each of the PC's (v10.0 on the development
machine, v9.0 on the client).

Regards
Simon


One Handed Man said:
Simon,

Good point, can you establish if the Msoffice DLL you need is on the
target ? I'm sorry but I have to leave now, let me know how you get
on.

Regards - OHM




Simon Verona wrote:
Tried that.. the document was originally on a mapped network drive,
but I copied it local.

I'm running out of options now!!

I'm just hoping that somebody has some inspiration for me!!!

I'm presuming that I don't have to do something special with the
install scripts to distribute/use the correct version of the Word
Objects??

Regards
Simon
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in
message One last thought !

Does your document reference use UNC pathnames IE (
\\SERVER\RESOURCE\DOCUMENTNAME ). If this is the case then maybe
your version of word running on Win2K does not support this from a
code point of view ( although I doubt it ).

One alternative may be to put the letterfile on the users hard disk
and change the path to a local direcectory\filename. At least this
would rule this out.

Regards - OHM


Simon Verona wrote:
yes, the letterfile does actually exist (I thought that this was
the problem myself)... It's the same letterfile on both my
development machine (on which it works) and the other PC (which
it doesn't) ... The document in question is on a networked drive
so it is *exactly* the same document.

You can open the document manually from either machine...

Regards
Simon

"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in
message Hi Simon,

This may seem like a really "Dumb" question, so if it is please
forgive me, but does letterfile actually exists in the path you
are looking for it in the system which does not work ?, I
presume it fails in the Try section because the objWord . .
.Activate?

Regards - OHM


Simon Verona wrote:
No, the versions of office are different...

However, this is a port of code that worked fine on vb6! I
suspect therefore that the office stuff should work the same...

Regards
Simon
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in
message First question is if all the versions of office are the same ?.
if not it may be that the class hierarchy has changed between
the two.


Regards - OHM


Simon Verona wrote:
I have a problem with automating MS Word through vb.net

My code is :

Dim objword As new Word.ApplicationClass
Try
objWord.Documents.Open(letterfile)
objWord.Documents.Item(letterfile).Activate()
Catch
MsgBox("Error - Word Not running properly - letterfile=" &
letterfile & vbCrLf & " Error = " & Err.Description)
openletter = True
Exit Function
End Try

This works fine on my development machine with Word XP
installed. However, when installed on another PC (with Word
2000 installed) it fails with an error "Object reference not
set to an instance of an object". I can tell from the task
manager that Word has started up and is running but beyond
that I can't work out what the problem is. I have distributed
the application simply by using the Windows installer project
which seems to distribute an interop.word library.

I don't know what else to try.... I'm presuming that as I
have Word XP on my development machine that any word code
should be backwardly compatible.

Any thoughts?

Regards
Simon
 
I suspect the problem is with the DLL. An application that is developed
with an older version of Word is forward compatible to newer versions of
Word. For exmaple, an application developed for Word 2000 will (usually)
work fine with Word XP or Word 2003. The reverse isn't true -- the Word
DLLs aren't backwards compatible.

You should have Word 2000 installed on your development machine, and your
project should refernce the Word/Office 9.0 type libraries (for Office 2000)
instead of the Office XP PIAs or the 10.0 type libraries. That will
probably solve your problem, or at least make it easier to debug.

Hope this helps,
Robert Jacobson
 
aha.... I run Office XP on my development machine...

Is there anyway of just installing the office 200 dll's on my machine (I
don't particularly want to downgrade)??

Regards
Simon
 
Word. For exmaple, an application developed for Word 2000 will (usually)
work fine with Word XP or Word 2003. The reverse isn't true -- the Word
DLLs aren't backwards compatible.

That's not true I'm afraid. Microsoft broke binary compatability between
Office 2000 and XP. Most of the functions are still there but you must not
use early binding - late binding must be used.

Rob.
 
So do I use the object libraries from XP or 2000 to get the job done? I
can probably change the code to late-binding using a OBJECT variable and a
createobject statement etc...

Regards
Simon
 
Use the Word 2000 object libraries. (Ideally, you should have Word 2000
installed on your test machine.) It should then work fine with later
versions of Word -- but test to make sure.
 
Use the Word 2000 object libraries. (Ideally, you should have Word 2000

Agreed but don't use early binding, e.g. replace

Dim MyDoc as Word.Document ' or whatever the right syntax is
MyDoc.SomeFunction

with

Dim MyDoc As Object
MyDoc.SomeFunction

This forces late binding which will work between Office 2000 and XP. I
suspect that some functions moved offets from the base of the Word library
thus breaking early binding.

It does mean unfortunately that you can't use autofill in when entering your
code which with the Word object model being so complex is a shame.

What you could do is temporarily declare MyDoc as Word.Document, get it
working and then replace it with MyDoc as Object

Cheers, Rob.
 
Back
Top