
07-14-2005, 09:05 AM
|
|
|
|
Re: Recursive Function + File searching to return path
Yes, you can call a sub from in a sub.
Trythis to get a file list:
With Application.FileSearch
.NewSearch
'Could use ThisWorkbook.Path in LookIn
.LookIn = "c:\"
.SearchSubFolders = True
'.Filename = "book1.xls"
.FileType = msoFileTypeExcelWorkbooks
If .Execute > 0 Then
For iCtr = 1 To .FoundFiles.Count
Cells(iCtr, 1).Value = .FoundFiles(iCtr)
Cells(iCtr, 2).Value = FileDateTime(.FoundFiles(iCtr))
Next iCtr
End If
End With
--
Damon Longworth
Don't miss out on the 2005 Excel User Conference
Sept 16th and 17th
Stockyards Hotel - Ft. Worth, Texas
www.ExcelUserConference.com
"ph8" <ph8.1s5rz9_1121342789.4701@excelforum-nospam.com> wrote in message
news:ph8.1s5rz9_1121342789.4701@excelforum-nospam.com...
>
> Hey folks, I need a little help.
>
> First and foremost, does Excel VBA support recursive functions/subs?
> (IE: can I call a sub from within the same sub?)
>
> Second. Does VBA have a way to browse through file directories? I have
> a file Hierarchy, and what I would love is for Excel to start at the
> top and for every .xls file it finds, put it in a list in the
> spreadsheet calling the 'search' macro. It should return the path of
> the file name. Since these spreadsheets are nested within directories,
> which are within directories, which are within directories, etc...
>
> In reality, I need a sub that starts in the directory where the file
> calling/initiating the sub is saved in. From there, it looks for
> (other) .xls files, if it doesn't find any, it will look in the first
> directory it sees. From that directory, it will look for a .xls file,
> if it finds one, it needs to return the path to that .xls file and add
> it to the next available spot on sheet2 of the initiating file. From
> there it will search the next directory for excel files or directories
> and keep going. Until all directories have been searched and all
> 'excel' files have been reported for.
>
> I don't entirely know if this makes any sense. I hope it does. It
> seemed like it would be more difficult to explain, which leads me to
> think I am missing something big.
>
> Anyways this seems like it would be easier if I could 'chat' to someone
> about this live over AIM or whatnot (because I may have other questions
> as i am going). I don't suppose any excel experts have some sort of
> chat handle/program that they can use while going about their business
> (I don't want to be an inconvenience). If you don't want to give it out
> publicly, please e-mail me with details (eph619@gmail.com). Thanks in
> advanced.
>
> I would appreciate any assistance or ideas with the issues above as
> well (on these forums). Thanks again!
>
>
> --
> ph8
> ------------------------------------------------------------------------
> ph8's Profile:
> http://www.excelforum.com/member.php...o&userid=19871
> View this thread: http://www.excelforum.com/showthread...hreadid=387116
>
|