open filename containing specific characters in known folder

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I will be grateful if anyone can give me some code to go to a known folder
and find and open a file that in its filename has say "PK26" so the fileaname
could be say "xyz PK26 abc.xls" or "PK26 zxqwer.xls" or whatever but
containing "PK26". I am specifically looking for "PK26" to be contained in
the name.

I basically need to loop down a list of part file names and open the
relevant file as above, do whatever then close the file and look for the next
one.
 
Look at Dir in VBA help, it should do what you want.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
try something like this, I do a pattern search with .FileSearch then open
each file that matches the pattern.
Sub OpenPatternFile()
Dim cnt As Long
With Application.FileSearch
.NewSearch
.LookIn = "C:\"
.Filename = "*PK26*.xls"
.SearchSubFolders = False
.Execute
For cnt = 1 To .FoundFiles.Count
Workbooks.Open .FoundFiles(1)
'Perform your operations
ActiveWorkbook.Close False
Next
End With
End Sub
 

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

Back
Top