Find filename of open file

I

Ian

I've tried, and failed, to successfully open a template as an xlt file
(rather than xls) so I'm trying a different method to achieve what I need.

My problem is this. Having opened a couple of files, I want to activate a
specific one. Based on template filename.xlt, the workbook _should_ be
filename1.xls, but this is not necessarily going to be the case. How can I
determine the filename of the open file? I can't use Dir as the file hasn't
been saved at this point.

Any ideas?

Ian
 
J

Jim Thomlinson

Something like this will give you the names of all open workbooks...

Sub Test
dim wbk as workbook

for each wbk in workbooks
msgbox wbk.name
next wbk
end sub
 
I

Ian

Hi Gary

Apparently this will give me the name of the active workbook, but isn't what
I need. With several files open, I want to return focus to a specific file
for which I only have a partial name (eg filenameXX.xls where XX is
unknown).

Ian
 
I

Ian

Thanks, Jim.

I've not tested this yet, but it looks like it'll do what I need. I should
be able to loop through the open workbooks until I find a match with the
partial filename I have, then activate the matched workbook.

Ian
 
I

Ian

Hi Jim

Works a treat, thanks. I still wish I knew why I couldn't OPEN the template
instead of creating a NEW FILE based on it, but at least I have a
workaround.

Ian
 

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