[AccessD] Getting ALL word instances

Colby, John JColby at dispec.com
Fri Jan 30 09:26:54 CST 2004


>What version of Word are you dealing with?

Office2K or XP

>Basically yyou need to keep track of if you open Word or are reusing an
already opened instance of Word and only closing Word if YOU created it. You
will still need to close your docs though.

That's what I thought.

Thanks,

John W. Colby
The database guy


-----Original Message-----
From: Bryan Carbonnell [mailto:Bryan_Carbonnell at cbc.ca]
Sent: Friday, January 30, 2004 9:29 AM
To: accessd at databaseadvisors.com
Subject: Re: [AccessD] Getting ALL word instances


> It LOOKS like when several word documents are open, each one is an
instance
> of word.  There is an icon in the toolbar for each document.  I have
the
> following code (which works, kind of):

What version of Word are you dealing with?

Word 2K (and Higher I think) actually only open one instance of Word,
but put each document in it's own "button" in the task bar.

If want to visually verify that you only have one instance open, have a
look at the Close buttons in the Upper right corner. If you have two
documents open, when looking at either document you should only have a
close button in the title bar if the docs are in the instance of Word.
If you have a close button in the tile bar AND the menu bar, then you
have two separate instances of Word open.

I see a couple of problems with your code. Basically what I don't see
is how you deal with Word not being opened at all.

Here is how I deal with automating word:

'Get pointer to Word Object
' Handle Error In-Line
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number = 429 Then
    'If we got an error, that means there was no Word Instance
    Set objWord = CreateObject("Word.Application")
    'Set Flag to let us know we opened Word
    bolOpenedWord = True
End If

'Make Word Instance visible
objWord.Visible = True
'Reset Error Handler
On Error GoTo 0

'Do your processing stuff here

'Time to close up shop
'Did we create the Word instance we are using
' or did we reuse an open instance?
If bolOpenedWord = True Then
    'We created an instance, so now we need to close it.
    objWord.Quit
End If
Set objWord = Nothing

Does this sort of answer your question?

Basically yyou need to keep track of if you open Word or are reusing an
already opened instance of Word and only closing Word if YOU created it.
You will still need to close your docs though.

Bryan Carbonnell
bryan_carbonnelL at cbc.ca

>>> jwcolby at colbyconsulting.com 30-Jan-04 8:58:19 AM >>>
Folks,

I am trying to clean up after my merge stuff.  If the user fails to
close
the document, I have to do so before I can continue.  My mail stuff
opens
two documents, which appear to be TWO instances of word.  Further the
user
may already have a document of their own open.

It LOOKS like when several word documents are open, each one is an
instance
of word.  There is an icon in the toolbar for each document.  I have
the
following code (which works, kind of):

Public objWord As Word.Application

Function OpenWord() As Word.Application
    On Error Resume Next
    Set objWord = GetObject(, "Word.Application")
    If objWord Is Nothing Then
    Else
        objWord.Visible = True
    End If
End Function

Function TestWrdClose()
    OpenWord
    objWord.Quit False
    Set objWord = Nothing
End Function

The problem is, that if I have three docs open, when I call
TestWrdClose ONE
TIME, all word docs close.  So....

I need to close any instances of word that I opened, yet leave any
instances
that THEY opened.  I know (think) I can use code like

First question... Is it possible to open an instance of Word and give
it a
"name" such that I can search for that "name", get a handle to that
instance, and then close it?.

Second question... I assume that in order to close it, all I need to do
is
use the application.close once I have a handle?

Or is it just a simple matter of closing all my own documents, then
seeing
if any documents are open, and if not closing the word instance?

John W. Colby
www.ColbyConsulting.com 


_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com 
http://databaseadvisors.com/mailman/listinfo/accessd 
Website: http://www.databaseadvisors.com
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com


More information about the AccessD mailing list