Retrieving the Path of a document open in a foreign Process !!

Is there a way of retrieving the full path of a document that is currently open in an Executable given the HWND or ProcessID of the executable ?

So for example :  Workbook A is currently open in an instance of Excel application. Can I get the  file path\name of workbook A just by knowing the Excel application window Handle or its ProcessId ?

Regards.

 
RAFAAJAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
dim appExcel as object
dim objBook as object

set appExcel = getobject(,"Excel.Application")
for each objBook in appExcel.Workbooks
  debug.print objBook.path, objBook.Name
next

0
RAFAAJAuthor Commented:
Thanks Angel but that is not what I am after . This will work consistently ONLY if there is ONE XL application running ....hence the idea of using the ProcessIDs or HWNDs instead of using GetObject Function.

In my scenario, there can be many instances of XL running at the same time so I would like to be able to get the Path & Name of each open workbook in each running instance.

Any idea how to solve this one ?..... I have been looking for an answer to this for a long time but no one has answered it so far.

Regards.
0
RAFAAJAuthor Commented:
Any takers ?

Thanks.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

nffvrxqgrcfqvvcCommented:
You can use EnumWindows API with a callback. What this does is throw out the hwnd of each window on the desktop which you can then simply use GeWindowText API to grab the captions of each window, even better is if you want to only capture specific windows then you can by checking for a specific classname this would rule out capturing captions that you don't want.
0
amebaCommented:
See http:Q_21125371.html "Get worksheet names..."
Code in last comment should give all workbook names for all excel applications
0
RAFAAJAuthor Commented:
Thanks everyone.

Ameba, I can't find the olelib.tlb Library via Tools > References... . I am running XL2002 in  MSO XP . Does this lib come by default with a standard Windows installation or is it like a third party control that I need to get it from a vendor or that has to be registered  ?

Any help would be much appreciated.

Thanks.
0
amebaCommented:
RAFAAJ,

http://www.mvps.org/emorcillo/en/code/vb6/index.shtml "OLELIB.TLB - OLE interfaces & functions v1.7"
You can unpack OLELIB.TLB from zip file.

Note that you don't have to distribute OLELIB.TLB file - everything needed will be included in your .EXE during compile time.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RAFAAJAuthor Commented:
Thanks ameba,

Sorry to be a pain but how do I register this LIB ? I mean what is the exact syntax ?

This is what I have done so far :

-I downloaded the zip file , unpacked it and I copied the whole unpacked files to a newly created folder(which I named TLB) which in turn I placed inside the Windows\sytem32 folder.

Now, which file among all the extracted ones do I register ?


Note : BTW, I am not using VB . I am using VBA so no real compiling.

I believe this LIB is just a wrapper for what can be achieved using API functions alone. Because I am using VBA, can I ask if there is a way of achiving this using APIs alone whithout the need for third party LIBs ?- that would be raelly helpful as I cannot compile code in VBA.

Thanks for your help.


0
amebaCommented:
RAFAAJ,
> I believe this LIB is just a wrapper for what can be achieved using
> API functions alone.

It is REQUIRED wrapper - without knowing the interface, you cannot access those functions.

I'm not sure I can help with VBA - I tested it in VB6: in VB IDE, I used Project > References > Browse... to add OLELIB.TLB and it worked.
In VBA, you should have equivalent of that.  If not, the question "Get worksheet names..." also mentions code, see http:Q_21125371.html#12025412


Some background info on type libraries and interface definition language can be found in http://www.devx.com/vb2themax/Article/19830 "IDL For VB Tutorial"
ROT functions are in system dlls, part of COM (component object model) and TLB is used to access them.
0
RAFAAJAuthor Commented:
Ameba,

Fantastic :)

I have managed to register the LIB and it worked beautifully !

Thanks very much indeed for helping me with this.

Just one more Q .  Will this  LIB  be always available for free so users can install it in their machines As & When needed ?

Regards.
0
amebaCommented:
I guess you will have to distribute OLELIB.TLB, since your app is not compiled.  It's free, there is even source code included (.inc files), so you can produce (using mktyplib.exe) smaller version with only interfaces you use, plus their dependencies.

I really hate when I get B. :-(
0
RAFAAJAuthor Commented:
Ameba,

Sorry about that B thing. I just chose a grade randomly .

I don't really know the exact meaning of all these Gradings ,Acepting posts ,Scorings...etc . I must say, I find this grading thing and , actually, the whole of this Forum USER INTERFACE really confusing and disappointing.

Imagine that I cannot even edit my posts because I just can't see an Edit button anywhere !..errrrr How annoying :(

Now, If you want to learn about the rules, apparently, one has to read thru pages and pages....Most people just don't have the time or patience to do that.

I wander :  ! Why make a site layout and rules so couterintuitive   ??????    !!!!!!!!!!!!!!!!!

Anyway,Can I change the Grade now ? and if so, how ? ... or is it too late ?

Regards.


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.