ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   open filename containing specific characters in known folder (https://www.excelbanter.com/excel-programming/377024-open-filename-containing-specific-characters-known-folder.html)

Spike

open filename containing specific characters in known folder
 
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.
--
with kind regards

Spike

Spike

open filename containing specific characters in known folder
 
I have sorted it using Dir and wildcard
--
with kind regards

Spike


"Spike" wrote:

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.
--
with kind regards

Spike


Bob Phillips

open filename containing specific characters in known folder
 
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)

"Spike" wrote in message
...
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.
--
with kind regards

Spike




Charles Chickering

open filename containing specific characters in known folder
 
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
--
Charles Chickering

"A good example is twice the value of good advice."


"Spike" wrote:

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.
--
with kind regards

Spike



All times are GMT +1. The time now is 09:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com