open Workbook path

  • Thread starter Thread starter Boba
  • Start date Start date
B

Boba

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.
 
Sub listum()
For Each wb In Workbooks
MsgBox (wb.Name & wb.Path)
Next
End Sub
 
Gary''s Student said:
Sub listum()
For Each wb In Workbooks
MsgBox (wb.Name & wb.Path)
Next
End Sub

Thank you for your prompt answer,
but what you suggest is VB (not VC)
version - and my Automation application
is written in C++.
 
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/
 
T Lavedas said:
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...
 
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(yournamefortheWorkbookObject.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/
 
T Lavedas said:

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.
 
Back
Top