Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 272
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Set specific default folder and/or drive to open - Excel 2007 RS Excel Discussion (Misc queries) 3 June 9th 09 02:17 AM
can anyone tell me how to set excel to open to a specific folder bdc1952 Excel Discussion (Misc queries) 1 March 20th 08 05:14 PM
How do you set Excel 2007 to open files in a specific folder? Opening to a specific folder Excel Discussion (Misc queries) 2 August 12th 07 02:58 AM
can excel automaticaly open file from specific folder sand Excel Discussion (Misc queries) 1 July 7th 07 03:56 PM
Open file with unknown extra characters at end of filename achidsey Excel Programming 1 October 19th 05 09:21 PM


All times are GMT +1. The time now is 05:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"