ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   open Workbook path (https://www.excelbanter.com/excel-programming/410588-open-workbook-path.html)

Boba

open Workbook path
 
Dear All;
I'd like to list all open workbooks from my VC application.
My first step was calling GetActiveObject; it returns
a pointer to IUnknown interface for Excel Application.
Now I can get the names of all loaded workbooks but I
also need their paths (Excel10 on Windows XP). Thanks.
Boba.




Gary''s Student

open Workbook path
 
Sub listum()
For Each wb In Workbooks
MsgBox (wb.Name & wb.Path)
Next
End Sub

--
Gary''s Student - gsnu2007h

Boba

open Workbook path
 
"Gary''s Student" wrote in message
...
Sub listum()
For Each wb In Workbooks
MsgBox (wb.Name & wb.Path)
Next
End Sub

--
Gary''s Student - gsnu2007h


Thank you for your prompt answer,
but what you suggest is VB (not VC)
version - and my Automation application
is written in C++.



T Lavedas

open Workbook path
 
On May 7, 1:18 pm, "Boba" wrote:
"Gary''s Student" wrote in message

...

Sub listum()
For Each wb In Workbooks
MsgBox (wb.Name & wb.Path)
Next
End Sub


--
Gary''s Student - gsnu2007h


Thank you for your prompt answer,
but what you suggest is VB (not VC)
version - and my Automation application
is written in C++.


He gave you all you need to know, regardless of exact syntax. The
point being, that however you are accessing the 'Names' of the
workbooks, if you simply replace the Name property with the Path
property, you have your answer, as in ...

var sWBPath = yournamefortheWorkbookObject.Path;

OK, is that C++ enough.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Boba

open Workbook path
 
"T Lavedas" wrote in message
...
He gave you all you need to know, regardless of exact syntax. The
point being, that however you are accessing the 'Names' of the
workbooks, if you simply replace the Name property with the Path
property, you have your answer, as in ...

var sWBPath = yournamefortheWorkbookObject.Path;

OK, is that C++ enough.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/


Hi, Tom;
The problem is that the Path property also
returns workbook name (not the file location).
I suspect it might have smth to do with the fact
that my VS is v.6 and is too old for XP. This
may be a good time for update...



T Lavedas

open Workbook path
 
On May 7, 1:57 pm, "Boba" wrote:
"T Lavedas" wrote in message

...

He gave you all you need to know, regardless of exact syntax. The
point being, that however you are accessing the 'Names' of the
workbooks, if you simply replace the Name property with the Path
property, you have your answer, as in ...


var sWBPath = yournamefortheWorkbookObject.Path;


OK, is that C++ enough.


Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/


Hi, Tom;
The problem is that the Path property also
returns workbook name (not the file location).
I suspect it might have smth to do with the fact
that my VS is v.6 and is too old for XP. This
may be a good time for update...


No, I doubt that it has anything to do with version. It's jaut that
Excel's definition (and some other interfaces, as well), interpret
Path to mean the entire pathspec to the file, as opposed to the parent
path to the folder that contains the file. You can either parse the
path to remove the name or invoke the FSO and use the
GetParentFolderName(path) method to do the parsing ...

var oFSO = new ActiveXObject("Scripting.FileSystemObject");
var sWBPath =
FSO.GetParentFolderName(yournamefortheWorkbookObje ct.Path);

This is JScript syntax, not C++, and there may be an equivalent parser
or another way to access the FSO, but hopefully it's close enough to
give you the idea.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Boba

open Workbook path
 
"T Lavedas" wrote in message
...
...


the only reason I'm posting this question is:
Path, Name, and Title are all the same ;(
Even if I have 2 workbooks like this open
c:\\SomeFolder\\File1.xls
c:\\DifferentFolder\\File1.xls
all 6 properties are "File1.xls" .
BTW, that same code applied to MS Word Application
works as expected.




All times are GMT +1. The time now is 07:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com