#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default FoundFiles

Is there a way, short of string manipulation functions to return the filename
only of a FoundFiles.Item ? I will be loading filenames into a List box
without their path. The current state of the code merely lists them in a
MsgBox, after removing the folder path selected by the GetFolderName function
(which uses Application.FileDialog). This method, however, will not remove
the remainder of the path from files in subfolders of the main folder.

Thank you for any assistance.

Sprinks

' Dimension variables.
Dim myarray()
Dim fs As Object
Dim i As Integer
Dim strMsg As String

' Declare filesearch object.
Set fs = Application.FileSearch

' Set folder to search.
With fs
.SearchSubFolders = True
.LookIn = GetFolderName()
End With

If fs.LookIn = "" Then
' User pressed Cancel
Exit Sub
End If

' Set file name to search for.
fs.Filename = "*.xls"

' Execute the file search, and check to see if the file(s) are
' present.
If fs.Execute 0 Then

' Redimension the array to the number of files found.
ReDim myarray(fs.FoundFiles.Count)

' Loop through all found file names and fill the array.
For i = 1 To fs.FoundFiles.Count
myarray(i) = fs.FoundFiles(i)
Next i
Else
' Display message if no files were found.
MsgBox "No files were found"
End If

strMsg = ""
For i = 1 To fs.FoundFiles.Count
strMsg = strMsg & Mid(fs.FoundFiles.Item(i), Len(fs.LookIn) + 2) &
vbCrLf
Next i

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

You can use the split function

v = split(.foundfiles(i),"\")
fname = v(ubound(v))

--
Regards,
Tom Ogilvy



"Sprinks" wrote:

Is there a way, short of string manipulation functions to return the filename
only of a FoundFiles.Item ? I will be loading filenames into a List box
without their path. The current state of the code merely lists them in a
MsgBox, after removing the folder path selected by the GetFolderName function
(which uses Application.FileDialog). This method, however, will not remove
the remainder of the path from files in subfolders of the main folder.

Thank you for any assistance.

Sprinks

' Dimension variables.
Dim myarray()
Dim fs As Object
Dim i As Integer
Dim strMsg As String

' Declare filesearch object.
Set fs = Application.FileSearch

' Set folder to search.
With fs
.SearchSubFolders = True
.LookIn = GetFolderName()
End With

If fs.LookIn = "" Then
' User pressed Cancel
Exit Sub
End If

' Set file name to search for.
fs.Filename = "*.xls"

' Execute the file search, and check to see if the file(s) are
' present.
If fs.Execute 0 Then

' Redimension the array to the number of files found.
ReDim myarray(fs.FoundFiles.Count)

' Loop through all found file names and fill the array.
For i = 1 To fs.FoundFiles.Count
myarray(i) = fs.FoundFiles(i)
Next i
Else
' Display message if no files were found.
MsgBox "No files were found"
End If

strMsg = ""
For i = 1 To fs.FoundFiles.Count
strMsg = strMsg & Mid(fs.FoundFiles.Item(i), Len(fs.LookIn) + 2) &
vbCrLf
Next i

MsgBox strMsg

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default FoundFiles

Great! Thanks, Tom.

Sprinks

"Tom Ogilvy" wrote:

You can use the split function

v = split(.foundfiles(i),"\")
fname = v(ubound(v))

--
Regards,
Tom Ogilvy



"Sprinks" wrote:

Is there a way, short of string manipulation functions to return the filename
only of a FoundFiles.Item ? I will be loading filenames into a List box
without their path. The current state of the code merely lists them in a
MsgBox, after removing the folder path selected by the GetFolderName function
(which uses Application.FileDialog). This method, however, will not remove
the remainder of the path from files in subfolders of the main folder.

Thank you for any assistance.

Sprinks

' Dimension variables.
Dim myarray()
Dim fs As Object
Dim i As Integer
Dim strMsg As String

' Declare filesearch object.
Set fs = Application.FileSearch

' Set folder to search.
With fs
.SearchSubFolders = True
.LookIn = GetFolderName()
End With

If fs.LookIn = "" Then
' User pressed Cancel
Exit Sub
End If

' Set file name to search for.
fs.Filename = "*.xls"

' Execute the file search, and check to see if the file(s) are
' present.
If fs.Execute 0 Then

' Redimension the array to the number of files found.
ReDim myarray(fs.FoundFiles.Count)

' Loop through all found file names and fill the array.
For i = 1 To fs.FoundFiles.Count
myarray(i) = fs.FoundFiles(i)
Next i
Else
' Display message if no files were found.
MsgBox "No files were found"
End If

strMsg = ""
For i = 1 To fs.FoundFiles.Count
strMsg = strMsg & Mid(fs.FoundFiles.Item(i), Len(fs.LookIn) + 2) &
vbCrLf
Next i

MsgBox strMsg

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
removing the file extension while listing files via foundfiles Jon[_21_] Excel Programming 7 April 15th 06 10:17 PM
Using FoundFiles to list by path and filename Jon[_21_] Excel Programming 2 April 15th 06 06:41 PM
Using .FoundFiles to list files by path and file name Jon[_21_] Excel Programming 0 April 12th 06 04:45 AM
.Foundfiles Question Shane Excel Programming 5 November 24th 05 04:46 AM


All times are GMT +1. The time now is 01:37 AM.

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"