How to get the "right" instance of an application?

T

TCook

I am familiar with the GetObject function in VB which will obtain a
reference to a running instance of an application. However, the GetObject
function is not specific in that instance (i.e. if there are multiple
instances of an application running, there is no way to guarantee which
instance will be obtained).

I am also familiar with the Tasks collection which is exposed in MS Word.
One can loop through these tasks and activate one if desired.

The above said, I was wondering if anyone knows how to:

A) Obtain a reference to a specific instance of an MS Office application

or;

B) Work with the tasks collection without using an instance of MS Word
(i.e. if I wanted to perform the same task from Excel, PowerPoint or
Outlook, how would I)?

Thanks & Regards,

Todd
 
S

Sam Hobbs

TCook said:
A) Obtain a reference to a specific instance of an MS Office application

Which Office application? I think the current versions of all of them are
limited to one instance. If you are developing for an older version, then
note that the solution is not likely to work with newer versions.

This is definitely not a common thing to do. You are not likely to get help
since it is so uncommon that no one here knows how to do it. I say that to
help you understand that if you can explain why you need to do this, then
you are more likely to get help with the problem that this solution is
intended to solve. In other words, why do you need to get a reference to a
specific instance of an MS Office application?
 
D

dm.unseen

Todd,

there are several possibelities:

1. For accessing Office App instances, this is possible, but probably
never done, You need to add all instances to the ROT yourself, and then
use a host of tricks to hook into the instance. The Book "Hardore
Visual Basic" (still somewhere on the net) should give you info, but
then you are on your own. I would not go there.

2 use Getobject("Myfile"). This will give you a handle to the office
instance that has this file open, or if it is not open, open the file
inside a running instance Since most Office apps can open files
exculsively, you could use this trick to get the instance with the file
you want. You still have no control over just any instance however.

3. Use a mediator activeX. This is an out of process VB ActiveX program
that only allows one single instance. Give it properties to allow you
to store Office App instance references globally in your windows
session. Your Office instances need to register their object handle
first though, so you also need to code the instance regsitering in
each office app seperatly. The advantage is you now have full control
over all office app instances that registered their reference with your
ActiveX.

DM Unseen
 
N

NickHK

Todd,
What is the "right" instance for your purposes ?

NickHK
P.S. This is the 3rd or 4th request this week to achieve this. Spooky.
 
C

Cindy M -WordMVP-

Hi Sam,
Which Office application? I think the current versions of all of them are
limited to one instance.
No, that's not the case. If you use New Word.Application or CreateObject it
will create a new instance of the application.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

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