RAFAAJ
asked on
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.
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.
ASKER
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.
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.
ASKER
Any takers ?
Thanks.
Thanks.
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.
See http:Q_21125371.html "Get worksheet names..."
Code in last comment should give all workbook names for all excel applications
Code in last comment should give all workbook names for all excel applications
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
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.
> 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.
ASKER
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.
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.
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. :-(
I really hate when I get B. :-(
ASKER
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.
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.
dim objBook as object
set appExcel = getobject(,"Excel.Applicat
for each objBook in appExcel.Workbooks
debug.print objBook.path, objBook.Name
next