Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default File Name List

Below is what I have put together to generate a list of all files located in a specific Directory. It generates the list and then puts it in column "A". In Column "B" it puts the last number in the name of the file after it removes the ".txt". My issue is I need to put the first letter of the fiel name in column "C". The only problem is the list it generates includes the entire path name ex: C:\My Documents\Mike\...\...\AlphaReport1.txt

I have it set that I get the "1" in coulmn "B", but I need to find a way to get the "A" in column "C". Any help would be great. I thought about trying to get it the same way I got the "1" out, but the file names won't always be the same length, and at this point I am lost as to what to do.

Sub FindFiles()
With Application.FileSearch
.NewSearch
.LookIn = ThisWorkbook.Path & "\ProgramData\FileData\" & "RawData"
.SearchSubFolders = False
.Filename = "*.txt"
.MatchTextExactly = True
.FileType = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
Cells(i, 1) = Right(.FoundFiles(i), (Len(.FoundFiles(i)) - Len(mypath) - 1))
Next i
For i = 1 To .FoundFiles.Count
Cells(i, 1).Value = Replace(Cells(i, 1).Value, ":\", "C:\")
Cells(i, 2).Value = Right(Cells(i, 1).Value, 5)
Cells(i, 2).Value = Replace(Cells(i, 2).Value, ".txt", "")
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub

Thanks for any advise or assistance you can give me.

Mike
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default File Name List

something like this to look from right to left should help
x = Application.Find("\", StrReverse(.FoundFiles(i))) - 2
You need to use StrReverse. If your version doesn't have it you can use this
in a regular module.

Public Function StrReverse(reverseString As String) As String
Dim i As Long
For i = Len(reverseString) To 1 Step -1
StrReverse = StrReverse & Mid(reverseString, i, 1)
Next i
End Function

--
Don Guillett
SalesAid Software

"Mike Etzkorn" wrote in message
...
Below is what I have put together to generate a list of all files located

in a specific Directory. It generates the list and then puts it in column
"A". In Column "B" it puts the last number in the name of the file after it
removes the ".txt". My issue is I need to put the first letter of the fiel
name in column "C". The only problem is the list it generates includes the
entire path name ex: C:\My Documents\Mike\...\...\AlphaReport1.txt

I have it set that I get the "1" in coulmn "B", but I need to find a way

to get the "A" in column "C". Any help would be great. I thought about
trying to get it the same way I got the "1" out, but the file names won't
always be the same length, and at this point I am lost as to what to do.

Sub FindFiles()
With Application.FileSearch
.NewSearch
.LookIn = ThisWorkbook.Path & "\ProgramData\FileData\" & "RawData"
.SearchSubFolders = False
.Filename = "*.txt"
.MatchTextExactly = True
.FileType = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
Cells(i, 1) = Right(.FoundFiles(i), (Len(.FoundFiles(i)) -

Len(mypath) - 1))
Next i
For i = 1 To .FoundFiles.Count
Cells(i, 1).Value = Replace(Cells(i, 1).Value, ":\", "C:\")
Cells(i, 2).Value = Right(Cells(i, 1).Value, 5)
Cells(i, 2).Value = Replace(Cells(i, 2).Value, ".txt", "")
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub

Thanks for any advise or assistance you can give me.

Mike



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default File Name List

Sub FindFiles()
Dim myPath as String
Dim lLen as Long, i as Long
myPath = ThisWorkbook.Path & "\ProgramData\FileData\RawData"
lLen = len(myPath) + 1
With Application.FileSearch
.NewSearch
.LookIn = mypath
.SearchSubFolders = False
.Filename = "*.txt"
' .MatchTextExactly = True
.FileType = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
Cells(i, 1) = Right(.FoundFiles(i), Len(.FoundFiles(i)) - lLen)
Cells(i, 2).Value = Replace(Right(Cells(i, 1).Value, 5), ".txt", "")
Cells(i, 3).Value = Left(Cells(i,1).Value,1)
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub

Might work unless you wanted the path in column 1.

--
Regards,
Tom Ogilvy


"Mike Etzkorn" wrote in message
...
Below is what I have put together to generate a list of all files located

in a specific Directory. It generates the list and then puts it in column
"A". In Column "B" it puts the last number in the name of the file after it
removes the ".txt". My issue is I need to put the first letter of the fiel
name in column "C". The only problem is the list it generates includes the
entire path name ex: C:\My Documents\Mike\...\...\AlphaReport1.txt

I have it set that I get the "1" in coulmn "B", but I need to find a way

to get the "A" in column "C". Any help would be great. I thought about
trying to get it the same way I got the "1" out, but the file names won't
always be the same length, and at this point I am lost as to what to do.

Sub FindFiles()
With Application.FileSearch
.NewSearch
.LookIn = ThisWorkbook.Path & "\ProgramData\FileData\" & "RawData"
.SearchSubFolders = False
.Filename = "*.txt"
.MatchTextExactly = True
.FileType = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
Cells(i, 1) = Right(.FoundFiles(i), (Len(.FoundFiles(i)) - Len(mypath)

- 1))
Next i
For i = 1 To .FoundFiles.Count
Cells(i, 1).Value = Replace(Cells(i, 1).Value, ":\", "C:\")
Cells(i, 2).Value = Right(Cells(i, 1).Value, 5)
Cells(i, 2).Value = Replace(Cells(i, 2).Value, ".txt", "")
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub

Thanks for any advise or assistance you can give me.

Mike



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default File Name List

Where exactly would I put that into my current macro?

Thanks,

Mike
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default File Name List

This would work except for I do still need the full path name in column "A" - since I use that to open the workbooks with outer macros. It there anyway to make what you provided me still have the full path in column "A".

Thanks,

Mike


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default File Name List

Sorry, I forgot to mention, I am running ExcelXP and WindowsXP if that helps.
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
How can I hide unused file types from file types list in save dial Estra Q Excel Discussion (Misc queries) 1 December 17th 09 12:36 PM
Clear the file open file name dropdown list Daniel.C[_2_] Excel Discussion (Misc queries) 8 October 23rd 08 09:47 AM
The 'Recently used file list' does not show up under the 'File' menu. David F Excel Worksheet Functions 4 June 6th 05 07:43 AM
Convert List box from excel file to VBA list box object baha[_2_] Excel Programming 0 November 22nd 03 05:06 PM
File list Felix Rode Excel Programming 0 November 14th 03 02:53 AM


All times are GMT +1. The time now is 03: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"