Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
I need a formula for Excel whose input is a string, and whose output is a
list of path\filename found for filenames containing the string. |
#2
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
Put your string in cell A1 and run:
Sub ListFiles() Dim s As String s = Range("A1").Value s2 = "*" & s & "*.*" With Application.FileSearch .NewSearch .LookIn = "C:" .SearchSubFolders = True .Filename = s2 .FileType = msoFileTypeAllFiles If .Execute() 0 Then MsgBox "There were " & .FoundFiles.Count & _ " file(s) found." For i = 1 To .FoundFiles.Count ActiveSheet.Cells(i + 1, 1).Value = _ .FoundFiles(i) Next i Else MsgBox "There were no files found." End If End With End Sub 1. the code is adapted from a Tom Ogilvy posting 2. it takes a long time to run (at least on my old computer) -- Gary's Student "hmm" wrote: I need a formula for Excel whose input is a string, and whose output is a list of path\filename found for filenames containing the string. |
#3
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
Thanks GS.
I tried your macro. It showed "There were no files found," even with strings for which I am sure a file exists (it would work from Windows search). In debug, the program skipped the "Then" and went to the "Else"; as if .Execute() was always zero. Watch values of s and s2 were as expected. Perhaps there is an error somewhere? "Gary''s Student" wrote: Put your string in cell A1 and run: Sub ListFiles() Dim s As String s = Range("A1").Value s2 = "*" & s & "*.*" With Application.FileSearch .NewSearch .LookIn = "C:" .SearchSubFolders = True .Filename = s2 .FileType = msoFileTypeAllFiles If .Execute() 0 Then MsgBox "There were " & .FoundFiles.Count & _ " file(s) found." For i = 1 To .FoundFiles.Count ActiveSheet.Cells(i + 1, 1).Value = _ .FoundFiles(i) Next i Else MsgBox "There were no files found." End If End With End Sub 1. the code is adapted from a Tom Ogilvy posting 2. it takes a long time to run (at least on my old computer) -- Gary's Student "hmm" wrote: I need a formula for Excel whose input is a string, and whose output is a list of path\filename found for filenames containing the string. |
#4
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
the routine looks only on the C drive. I tried putting
arte in A1 and got stuff like: C:\Documents and Settings\All Users\Application Data\Webroot\Spy Sweeper\SpySweeperGettingStarted.chm C:\Documents and Settings\All Users\Desktop\Adobe Photoshop Album Starter Edition 3.0.lnk C:\Documents and Settings\All Users\Start Menu\Programs\Adobe\Adobe Photoshop Album Starter Edition 3.0.lnk C:\Documents and Settings\All Users\Start Menu\Programs\Creative\Documentation\Getting Started Manual.lnk C:\Documents and Settings\All Users\Start Menu\Programs\EPSON\Film Factory\EPSON PhotoStarter3.0.lnk C:\Documents and Settings\All Users\Start Menu\Programs\EPSON\Film Factory\Getting Started Guide.lnk C:\Documents and Settings\All Users\Start Menu\Programs\Games\GameChannel\Blackhawk Striker\Help.lnk -- Gary''s Student "hmm" wrote: Thanks GS. I tried your macro. It showed "There were no files found," even with strings for which I am sure a file exists (it would work from Windows search). In debug, the program skipped the "Then" and went to the "Else"; as if .Execute() was always zero. Watch values of s and s2 were as expected. Perhaps there is an error somewhere? "Gary''s Student" wrote: Put your string in cell A1 and run: Sub ListFiles() Dim s As String s = Range("A1").Value s2 = "*" & s & "*.*" With Application.FileSearch .NewSearch .LookIn = "C:" .SearchSubFolders = True .Filename = s2 .FileType = msoFileTypeAllFiles If .Execute() 0 Then MsgBox "There were " & .FoundFiles.Count & _ " file(s) found." For i = 1 To .FoundFiles.Count ActiveSheet.Cells(i + 1, 1).Value = _ .FoundFiles(i) Next i Else MsgBox "There were no files found." End If End With End Sub 1. the code is adapted from a Tom Ogilvy posting 2. it takes a long time to run (at least on my old computer) -- Gary's Student "hmm" wrote: I need a formula for Excel whose input is a string, and whose output is a list of path\filename found for filenames containing the string. |
#5
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
Thanks Gary; it works. The trick is that it will only search folders that
are offspring of the Excel file's folder. Can it be implemented in the form of a function, so that I can insert it in a table? "Gary''s Student" wrote: the routine looks only on the C drive. I tried putting arte in A1 and got stuff like: C:\Documents and Settings\All Users\Application Data\Webroot\Spy Sweeper\SpySweeperGettingStarted.chm C:\Documents and Settings\All Users\Desktop\Adobe Photoshop Album Starter Edition 3.0.lnk C:\Documents and Settings\All Users\Start Menu\Programs\Adobe\Adobe Photoshop Album Starter Edition 3.0.lnk C:\Documents and Settings\All Users\Start Menu\Programs\Creative\Documentation\Getting Started Manual.lnk C:\Documents and Settings\All Users\Start Menu\Programs\EPSON\Film Factory\EPSON PhotoStarter3.0.lnk C:\Documents and Settings\All Users\Start Menu\Programs\EPSON\Film Factory\Getting Started Guide.lnk C:\Documents and Settings\All Users\Start Menu\Programs\Games\GameChannel\Blackhawk Striker\Help.lnk -- Gary''s Student "hmm" wrote: Thanks GS. I tried your macro. It showed "There were no files found," even with strings for which I am sure a file exists (it would work from Windows search). In debug, the program skipped the "Then" and went to the "Else"; as if .Execute() was always zero. Watch values of s and s2 were as expected. Perhaps there is an error somewhere? "Gary''s Student" wrote: Put your string in cell A1 and run: Sub ListFiles() Dim s As String s = Range("A1").Value s2 = "*" & s & "*.*" With Application.FileSearch .NewSearch .LookIn = "C:" .SearchSubFolders = True .Filename = s2 .FileType = msoFileTypeAllFiles If .Execute() 0 Then MsgBox "There were " & .FoundFiles.Count & _ " file(s) found." For i = 1 To .FoundFiles.Count ActiveSheet.Cells(i + 1, 1).Value = _ .FoundFiles(i) Next i Else MsgBox "There were no files found." End If End With End Sub 1. the code is adapted from a Tom Ogilvy posting 2. it takes a long time to run (at least on my old computer) -- Gary's Student "hmm" wrote: I need a formula for Excel whose input is a string, and whose output is a list of path\filename found for filenames containing the string. |
#6
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
Check back tomorow
-- Gary''s Student "hmm" wrote: Thanks Gary; it works. The trick is that it will only search folders that are offspring of the Excel file's folder. Can it be implemented in the form of a function, so that I can insert it in a table? "Gary''s Student" wrote: the routine looks only on the C drive. I tried putting arte in A1 and got stuff like: C:\Documents and Settings\All Users\Application Data\Webroot\Spy Sweeper\SpySweeperGettingStarted.chm C:\Documents and Settings\All Users\Desktop\Adobe Photoshop Album Starter Edition 3.0.lnk C:\Documents and Settings\All Users\Start Menu\Programs\Adobe\Adobe Photoshop Album Starter Edition 3.0.lnk C:\Documents and Settings\All Users\Start Menu\Programs\Creative\Documentation\Getting Started Manual.lnk C:\Documents and Settings\All Users\Start Menu\Programs\EPSON\Film Factory\EPSON PhotoStarter3.0.lnk C:\Documents and Settings\All Users\Start Menu\Programs\EPSON\Film Factory\Getting Started Guide.lnk C:\Documents and Settings\All Users\Start Menu\Programs\Games\GameChannel\Blackhawk Striker\Help.lnk -- Gary''s Student "hmm" wrote: Thanks GS. I tried your macro. It showed "There were no files found," even with strings for which I am sure a file exists (it would work from Windows search). In debug, the program skipped the "Then" and went to the "Else"; as if .Execute() was always zero. Watch values of s and s2 were as expected. Perhaps there is an error somewhere? "Gary''s Student" wrote: Put your string in cell A1 and run: Sub ListFiles() Dim s As String s = Range("A1").Value s2 = "*" & s & "*.*" With Application.FileSearch .NewSearch .LookIn = "C:" .SearchSubFolders = True .Filename = s2 .FileType = msoFileTypeAllFiles If .Execute() 0 Then MsgBox "There were " & .FoundFiles.Count & _ " file(s) found." For i = 1 To .FoundFiles.Count ActiveSheet.Cells(i + 1, 1).Value = _ .FoundFiles(i) Next i Else MsgBox "There were no files found." End If End With End Sub 1. the code is adapted from a Tom Ogilvy posting 2. it takes a long time to run (at least on my old computer) -- Gary's Student "hmm" wrote: I need a formula for Excel whose input is a string, and whose output is a list of path\filename found for filenames containing the string. |
#7
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
Another strange thing: I keep a shortcut, to the Excel file containing the
macro, in a folder on my desktop. When the Excel file containing the macro is opened directly from its own folder, the macro has worked fine. But if I open it using the shortcut, the macro will not find files every time (i.e., sometimes yes, sometimes no). Apparently, in some cases the macro obtains the information about the working folder from the folder from which the workbook or shortcut was opened, and will only search the at folder level and below. Do you know whether or not this is the source of this bizarre problem? And if it is, is there any way around it, so that the macro will at least begin its search at the actual folder in which its its Excel file resides? (This is besides the problem that it will not start at the top, C:, as specified in the code, which I can deal with.) "Gary''s Student" wrote: the routine looks only on the C drive. I tried putting arte in A1 and got stuff like: C:\Documents and Settings\All Users\Application Data\Webroot\Spy Sweeper\SpySweeperGettingStarted.chm C:\Documents and Settings\All Users\Desktop\Adobe Photoshop Album Starter Edition 3.0.lnk C:\Documents and Settings\All Users\Start Menu\Programs\Adobe\Adobe Photoshop Album Starter Edition 3.0.lnk C:\Documents and Settings\All Users\Start Menu\Programs\Creative\Documentation\Getting Started Manual.lnk C:\Documents and Settings\All Users\Start Menu\Programs\EPSON\Film Factory\EPSON PhotoStarter3.0.lnk C:\Documents and Settings\All Users\Start Menu\Programs\EPSON\Film Factory\Getting Started Guide.lnk C:\Documents and Settings\All Users\Start Menu\Programs\Games\GameChannel\Blackhawk Striker\Help.lnk -- Gary''s Student "hmm" wrote: Thanks GS. I tried your macro. It showed "There were no files found," even with strings for which I am sure a file exists (it would work from Windows search). In debug, the program skipped the "Then" and went to the "Else"; as if .Execute() was always zero. Watch values of s and s2 were as expected. Perhaps there is an error somewhere? "Gary''s Student" wrote: Put your string in cell A1 and run: Sub ListFiles() Dim s As String s = Range("A1").Value s2 = "*" & s & "*.*" With Application.FileSearch .NewSearch .LookIn = "C:" .SearchSubFolders = True .Filename = s2 .FileType = msoFileTypeAllFiles If .Execute() 0 Then MsgBox "There were " & .FoundFiles.Count & _ " file(s) found." For i = 1 To .FoundFiles.Count ActiveSheet.Cells(i + 1, 1).Value = _ .FoundFiles(i) Next i Else MsgBox "There were no files found." End If End With End Sub 1. the code is adapted from a Tom Ogilvy posting 2. it takes a long time to run (at least on my old computer) -- Gary's Student "hmm" wrote: I need a formula for Excel whose input is a string, and whose output is a list of path\filename found for filenames containing the string. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
search for a word in csv file | Excel Discussion (Misc queries) | |||
Linking a worksheet from a different excel file | Excel Discussion (Misc queries) | |||
Retrieve data from all of the worksheet within the file | Excel Worksheet Functions | |||
Turning a text file name into a search and linking the file as a hyperlink | Excel Discussion (Misc queries) | |||
Links picking up values from an older version of linked file | Links and Linking in Excel |