Files In A Subdirectory

S

Sheldon Potolsky

From Excel VBA, with a spreadsheet open, I would like to store the
list of all files ending in .XLS, in filename order, in the directory
that spreadsheet is in. I would then want to process each of those
files (in filename order) and, based on a certain string I'm looking
for within the filename, do some processing based on that filename.
It's probably pretty straightforward but I would appreciate any code
suggestions anyone may have.
Thank you,
Sheldon
 
J

Joel

Try soemthing like this. I sometimes have problem with a search pattern like

"*abc*.xls" so I did the compare in two steps. First look for XLS files
then use INSTR to find the particular string you want to match.

Folder = "C:\temp"
First = true
do
if First = True then
FName = Dir(Folder & "\*.xls)
First = False
else
FName = Dir()
end if
if FName <> "" then
if instr(FName,"Search String") > 0 then
'Enter Your code here
end if
end if
loop while FName <> ""
 
S

Sheldon Potolsky

Thanks Joel; I've incorporated your code and it will work very well.
There was one typo:
FName = Dir(Folder & "\*.xls) should be
FName = Dir(Folder & "\*.xls") 2nd double quote added
Sheldon
 

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