Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Set specific default folder and/or drive to open - Excel 2007 | Excel Discussion (Misc queries) | |||
can anyone tell me how to set excel to open to a specific folder | Excel Discussion (Misc queries) | |||
How do you set Excel 2007 to open files in a specific folder? | Excel Discussion (Misc queries) | |||
can excel automaticaly open file from specific folder | Excel Discussion (Misc queries) | |||
Open file with unknown extra characters at end of filename | Excel Programming |