Extract Workbook name from pathname ?

D

Don Wiss

Using Application.GetOpenFilename I can find what file the user would like
to open. But before opening I want to be sure the file isn't already open.
Having the filename I can loop through the set of Application.Workbooks and
check. Problem is the GetOpenFilename returns the full pathname, and
Workbooks is a list of filenames only. So how do I easily extract the
filename from the pathname? I looked around and could not find a function.
If I have to I can loop through the name, find the slash (or colon), and do
a Right. But I would think that there is an easier way.

Thanks, Don <donwiss at panix.com>.
 
D

Don Wiss

Try ActiveWorkbook.Path

Uh, how does that help me? I have a pathname in a string variable. (A
pathname in a string variable is the result of GetOpenFilename.) What
ActiveWorkbook I have open, and is running the macro, is irrelevant to the
problem.

Don <donwiss at panix.com>.
 
T

Tom Ogilvy

fName = Application.GetOpenFileName()
for each bk in Workbooks
if ucase(bk.fullname) = ucase(fName) then
' workbook is open
end if
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top