?
Solved

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

Posted on 2006-04-26
12
Medium Priority
?
337 Views
Last Modified: 2010-04-07
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.

 
0
Comment
Question by:RAFAAJ
12 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16542339
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
 

Author Comment

by:RAFAAJ
ID: 16542911
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
 

Author Comment

by:RAFAAJ
ID: 16544067
Any takers ?

Thanks.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 16544522
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
 
LVL 15

Expert Comment

by:ameba
ID: 16544716
See http:Q_21125371.html "Get worksheet names..."
Code in last comment should give all workbook names for all excel applications
0
 

Author Comment

by:RAFAAJ
ID: 16547881
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
 
LVL 15

Accepted Solution

by:
ameba earned 375 total points
ID: 16548094
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
 

Author Comment

by:RAFAAJ
ID: 16550725
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
 
LVL 15

Expert Comment

by:ameba
ID: 16550962
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
 

Author Comment

by:RAFAAJ
ID: 16552148
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
 
LVL 15

Expert Comment

by:ameba
ID: 16552312
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
 

Author Comment

by:RAFAAJ
ID: 16552473
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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month16 days, 13 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question