Re: Word Automation: instance running, but can't use it? by Jezebel
Jezebel
Tue Aug 03 16:11:37 CDT 2004
set ObjWord = nothing doesn't do anything at the Word end; it only clears
your app's reference to Word. You need to quit Word first:
objWord.Quit
Be aware that there are various problems you can trigger in your code that
will prevent Word closing. Typically unhandled errors, or documents still
open (even if not visible) that Word thinks need saving.
"kiln" <kiln@brick-like.com> wrote in message
news:MPG.1b794b1bd4564029898a2@msnews.microsoft.com...
> OK, thanks, that makes sense. I was patching together code bits and am
> aware of the early/late binding issues, but am quite rusty with
> automation these days.
>
> I'll remove the early binding ref and code in this case. It made a big
> difference to fix that one line!
>
> Re: what happens if the user already has the document open? Good
> question!
>
> Also, I'm not sure how to deal with set objWord = Nothing; it doesn't
> seem to shut down word if I include it at the end of that sub.
>
> Thanks again!
>
> In article <e$rm$LSeEHA.1652@TK2MSFTNGP09.phx.gbl>,
> dwarves@heaven.com.kr says...
> > The problem is that the object you create (objWord) is not the object
you
> > are using to open the document. Your code has a mixture of early and
late
> > binding, and your problem is a consequence of that confusion.
> >
> > Early binding means that you have added a reference to the Word library
to
> > the project's references (which you've obviously done), and you declare
your
> > object variables explicitly, as in Dim oDoc As Word.Document. You could
> > similarly use
> >
> > Dim objWord as Word.Application
> >
> > and instantiate it using
> >
> > Set objWord = [new] Word.Application
> >
> > The alternative is that you not have the project reference to Word, and
> > declare all the variables as Object. This is a little harder to code
because
> > you don't get the Intellisense prompts and syntax checking; but it makes
> > your program independent of the version of Word the user has on their
> > machine.
> >
> >
> > However, your serious problem is this line: Set oDoc =
> > Word.Documents.Open(strMyDoc)
> >
> > This opens the document with an implicit reference to the Word
application;
> > not to objWord.
> >
> > You should have: Set oDoc = objWord.Documents.Open(strMyDoc)
> >
> > As a separate issue: what happens if the user already has the document
open?
> >
> >
> >
> >
> >
> >
> > "kiln" <kiln@brick-like.com> wrote in message
> > news:MPG.1b78c825cedf5d129898a0@msnews.microsoft.com...
> > > I have an Access 2000 app were a user may open Word docs, the path to
> > > the doc being stored in the db. I have this problem were if I open a
> > > word doc via code, and the user then closes word, the next time the
user
> > > requests a word doc, it doesn't fly. An instance of Word *is* created,
> > > you can see it in task manager (only one instance). There is no Word
> > > instance in the period between the first and second request. What am I
> > > doing wrong? Why doesn't the code below utilize this running instance
of
> > > Word (word 2002)?
> > >
> > > Some of this code comes from the Access Web, I'll not include the call
> > > that tests for a running instace of word (fIsAppRunning()), it works