Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default searching filenames

Hi,

I have a master spreadsheet which contains a list of other spreadsheets
from which I want to extract data to a csv file. To do this the user
simply selects a spreadsheet and hits extract and the data from this
spreadsheet is extracted to a csv file. The location of the user
psreadsheet is defined in the master spreadsheet. Problem I have is
that some of the spreadsheets in the list have the date in the filename
therefore the filename is never the same.

For example: 000036 Valuation 31 May 2006.xls

I need to know how to do 3 things:

1. Search a specific directory for file containing the text 'Valuation'
in the filename.
2. Select the last updated file in a specific directory to be selected
by the master spreadsheet.
3. The master spreadsheet currently looks for the full name of the file
to process. When the user selects a specific spreadsheet the filename
is passed as a variable therefore the correct spreadsheet can be
processed. In the situation described what would I define as the
filename as I am in actual fact searching the filename for a text
string (e.g. Valuation not 000036 Valuation 31 May 2006.xls ). Can I
use some kind of wildcard around the text Valuation?

Thanks!!
Steve

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default searching filenames


Sub OpenFile()
Dim sname As String, dt As Date
Dim s As String, maxDt As Date
Dim bk As Workbook, sPath As String
sPath = "C:\Data\"
sname = Dir(sPath & "*valuation*.xls")
Do While sname < ""
dt = FileDateTime(sPath & sname)
If dt maxDt Then
maxDt = dt
s = sname
End If
sname = Dir
Loop

Set bk = Workbooks.Open(sPath & s)

End Sub

--
Regards,
Tom Ogilvy


" wrote:

Hi,

I have a master spreadsheet which contains a list of other spreadsheets
from which I want to extract data to a csv file. To do this the user
simply selects a spreadsheet and hits extract and the data from this
spreadsheet is extracted to a csv file. The location of the user
psreadsheet is defined in the master spreadsheet. Problem I have is
that some of the spreadsheets in the list have the date in the filename
therefore the filename is never the same.

For example: 000036 Valuation 31 May 2006.xls

I need to know how to do 3 things:

1. Search a specific directory for file containing the text 'Valuation'
in the filename.
2. Select the last updated file in a specific directory to be selected
by the master spreadsheet.
3. The master spreadsheet currently looks for the full name of the file
to process. When the user selects a specific spreadsheet the filename
is passed as a variable therefore the correct spreadsheet can be
processed. In the situation described what would I define as the
filename as I am in actual fact searching the filename for a text
string (e.g. Valuation not 000036 Valuation 31 May 2006.xls ). Can I
use some kind of wildcard around the text Valuation?

Thanks!!
Steve


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
Filenames and formulae SimoninParis Excel Worksheet Functions 4 September 25th 09 04:21 PM
Searching, matching then searching another list based on the match A.S. Excel Discussion (Misc queries) 1 December 13th 06 05:08 AM
getting filenames jim9912 Excel Programming 3 March 30th 06 05:55 PM
Getting filenames via VBA Andrew Excel Programming 5 April 15th 05 12:41 PM
Filenames In Loops JEff Excel Programming 2 January 14th 05 06:43 AM


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

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

About Us

"It's about Microsoft Excel"