PC Review


Reply
Thread Tools Rate Thread

Calling Word (Ugh)

 
 
Scupper
Guest
Posts: n/a
 
      12th Dec 2003
I am working on adapting a process currently handled by VBA functions in
a Word template, moving to a VB.NET app that calls Word only when
necessary to manipulate documents (essentially, it is calling up a
dataset, writing it to a Word-readable mergefile, and then opening up
one of a number of templates and merging the data).

The application is working well on my development machine, which has
Word 2000 installed.

However ... I need it to work even if the user only has Word 97, and
there it becomes tricky.

This code works fine on the development machine:

'----------------------------------------------
Const ERR_APP_NOTRUNNING As Long = 429

Dim oWord As Word.ApplicationClass
Dim oDoc As Word.DocumentClass

Try
oWord = GetObject(, "Word.ApplicationClass")
Catch When Err.Number = ERR_APP_NOTRUNNING
oWord = New Word.ApplicationClass
End Try

With oWord
oDoc = .Documents.Add(strPath & strTemplate, , , True)
.ActiveDocument.MailMerge.MainDocumentType =
Word.WdMailMergeMainDocType.wdFormLetters

'... and so on

'-----------------------------------------------

But on a machine running Word 97, I get a type-91, "Object reference not
set to instance of an object" error on the "oDoc = ..." line.

An instance of Word is opening up, but I cannot seem to do anything with
it.

My questions:

Is there a better way to do this?
Is there a good way to support multiple potential external app versions?

Any and all help in this would be much appreciated, as this project has
gone well beyond its expected development time.
 
Reply With Quote
 
 
 
 
CJ Taylor
Guest
Posts: n/a
 
      12th Dec 2003
Could be the versioning of the system. If you want it to be that backwards
compatible then you might want to read up on the office 97 object model (if
you can find it =)) and make sure that it supports Doc.Add

Could be an interface that was added later down the road and isn't
compatible... Lots of things. =)

-CJ



"Scupper" <scupperAThotmailDOTcom> wrote in message
news:Xns944F5FE533318scupperhotmailcom@207.46.248.16...
> I am working on adapting a process currently handled by VBA functions in
> a Word template, moving to a VB.NET app that calls Word only when
> necessary to manipulate documents (essentially, it is calling up a
> dataset, writing it to a Word-readable mergefile, and then opening up
> one of a number of templates and merging the data).
>
> The application is working well on my development machine, which has
> Word 2000 installed.
>
> However ... I need it to work even if the user only has Word 97, and
> there it becomes tricky.
>
> This code works fine on the development machine:
>
> '----------------------------------------------
> Const ERR_APP_NOTRUNNING As Long = 429
>
> Dim oWord As Word.ApplicationClass
> Dim oDoc As Word.DocumentClass
>
> Try
> oWord = GetObject(, "Word.ApplicationClass")
> Catch When Err.Number = ERR_APP_NOTRUNNING
> oWord = New Word.ApplicationClass
> End Try
>
> With oWord
> oDoc = .Documents.Add(strPath & strTemplate, , , True)
> .ActiveDocument.MailMerge.MainDocumentType =
> Word.WdMailMergeMainDocType.wdFormLetters
>
> '... and so on
>
> '-----------------------------------------------
>
> But on a machine running Word 97, I get a type-91, "Object reference not
> set to instance of an object" error on the "oDoc = ..." line.
>
> An instance of Word is opening up, but I cannot seem to do anything with
> it.
>
> My questions:
>
> Is there a better way to do this?
> Is there a good way to support multiple potential external app versions?
>
> Any and all help in this would be much appreciated, as this project has
> gone well beyond its expected development time.



 
Reply With Quote
 
One Handed Man [ OHM# ]
Guest
Posts: n/a
 
      12th Dec 2003
The object is probably called something else in Word97. You'll need to check
the object hierarchy for that version and then you will find the object is
not in the reference you have already added to your project.

Regards - OHM#


Scupper wrote:
> I am working on adapting a process currently handled by VBA functions
> in a Word template, moving to a VB.NET app that calls Word only when
> necessary to manipulate documents (essentially, it is calling up a
> dataset, writing it to a Word-readable mergefile, and then opening up
> one of a number of templates and merging the data).
>
> The application is working well on my development machine, which has
> Word 2000 installed.
>
> However ... I need it to work even if the user only has Word 97, and
> there it becomes tricky.
>
> This code works fine on the development machine:
>
> '----------------------------------------------
> Const ERR_APP_NOTRUNNING As Long = 429
>
> Dim oWord As Word.ApplicationClass
> Dim oDoc As Word.DocumentClass
>
> Try
> oWord = GetObject(, "Word.ApplicationClass")
> Catch When Err.Number = ERR_APP_NOTRUNNING
> oWord = New Word.ApplicationClass
> End Try
>
> With oWord
> oDoc = .Documents.Add(strPath & strTemplate, , , True)
> .ActiveDocument.MailMerge.MainDocumentType =
> Word.WdMailMergeMainDocType.wdFormLetters
>
> '... and so on
>
> '-----------------------------------------------
>
> But on a machine running Word 97, I get a type-91, "Object reference
> not set to instance of an object" error on the "oDoc = ..." line.
>
> An instance of Word is opening up, but I cannot seem to do anything
> with it.
>
> My questions:
>
> Is there a better way to do this?
> Is there a good way to support multiple potential external app
> versions?
>
> Any and all help in this would be much appreciated, as this project
> has gone well beyond its expected development time.


Regards - OHM# (E-Mail Removed)


 
Reply With Quote
 
Mike Bulava
Guest
Posts: n/a
 
      12th Dec 2003
Try late binding to Word rather then referencing it(Kill the reference, and
declare oDoc and oWord as object).. I've had nothing but problems using
Multiple Versions of Office Products when early binding. And I think some
one once told me that once you compile on a station with one version of
Office the program will not function on any other version of office..


"Scupper" <scupperAThotmailDOTcom> wrote in message
news:Xns944F5FE533318scupperhotmailcom@207.46.248.16...
> I am working on adapting a process currently handled by VBA functions in
> a Word template, moving to a VB.NET app that calls Word only when
> necessary to manipulate documents (essentially, it is calling up a
> dataset, writing it to a Word-readable mergefile, and then opening up
> one of a number of templates and merging the data).
>
> The application is working well on my development machine, which has
> Word 2000 installed.
>
> However ... I need it to work even if the user only has Word 97, and
> there it becomes tricky.
>
> This code works fine on the development machine:
>
> '----------------------------------------------
> Const ERR_APP_NOTRUNNING As Long = 429
>
> Dim oWord As Word.ApplicationClass
> Dim oDoc As Word.DocumentClass
>
> Try
> oWord = GetObject(, "Word.ApplicationClass")
> Catch When Err.Number = ERR_APP_NOTRUNNING
> oWord = New Word.ApplicationClass
> End Try
>
> With oWord
> oDoc = .Documents.Add(strPath & strTemplate, , , True)
> .ActiveDocument.MailMerge.MainDocumentType =
> Word.WdMailMergeMainDocType.wdFormLetters
>
> '... and so on
>
> '-----------------------------------------------
>
> But on a machine running Word 97, I get a type-91, "Object reference not
> set to instance of an object" error on the "oDoc = ..." line.
>
> An instance of Word is opening up, but I cannot seem to do anything with
> it.
>
> My questions:
>
> Is there a better way to do this?
> Is there a good way to support multiple potential external app versions?
>
> Any and all help in this would be much appreciated, as this project has
> gone well beyond its expected development time.



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
calling ms word Southern at Heart Microsoft Outlook VBA Programming 1 25th Feb 2008 06:16 AM
'Type Mismatch' exception when calling Word.Application.Documents.Open method in Office (Word) 2003 PIA from C# webstuff@urbanperspective.net Microsoft C# .NET 1 18th Oct 2005 05:37 PM
calling word from .net sudha Microsoft Dot NET 2 17th Nov 2003 02:37 PM
Calling Word in Access app causes Word not responding zxl Microsoft Access 2 28th Aug 2003 05:42 PM
Re: calling word Heiko Microsoft Excel Programming 0 9th Jul 2003 06:32 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:43 PM.