Code:
Public FS As New FileSystemObject
Public FSfolder As Folder
Public subfolder As Folder
Public i As Integer
Public existingRange As Range
'---------------------------------------------------------------------------------------
Sub updateProjects()
Dim strStartPath As String
Set existingRange = Range("G1").EntireColumn
strStartPath = "C:\Test\" 'Set Root Filepath
i = (Cells(Rows.Count, 7).End(xlUp).Offset(1).Row) - 1 'Start First Blank Row (At End)
Call ScanFolder(strStartPath, i) 'Call Folder List Macro
End Sub
'---------------------------------------------------------------------------------------
Sub ScanFolder(sFolderPath As String, i As Integer)
Set FSfolder = FS.GetFolder(sFolderPath)
For Each subfolder In FSfolder.SubFolders
DoEvents
Call ScanFolder(sFolderPath, i) 'Recursion
i = i + 1
'If IsInArray = Not IsError(Application.Match(subfolder, existingRange, 0)) Then 'Prevent Doubles
Worksheets("Library").Hyperlinks.Add Anchor:=Worksheets("Library").Cells(i, 6), _
Address:=sFolderPath 'Add Hyperlink
'Address:=subfolder 'Add Hyperlink
Worksheets("Library").Cells(i, 7) = sFolderPath 'Add Search Key Used To Prevent Doubles
'End If
Next subfolder
Set FSfolder = Nothing
End Sub
<tbody>[TR]
[TD]Stuff[/TD]
[TD]Stuff[/TD]
[TD]Stuff[/TD]
[TD]Stuff[/TD]
[TD]Stuff[/TD]
[TD]File Location[/TD]
[TD]Do Not Touch This Column[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Hyperlink[/TD]
[TD]String of Hyperlink Filepath[/TD]
[/TR]
</tbody>[/TABLE]
Good day everyone,
This keeps giving me a stack overflow error (out of space) on it's first iteration. Basically what I'm trying to do is give it a root filepath, then add hyperlinks (preventing doubles) for each folder and subfolder within that root folder.
Root>Level 1>Level 2>Level 3
I only need Level 3 folders to be listed, or alternatively if a particular Level 2 has no subfolders, list that instead. However I'll settle for getting the core code working at the moment :D
Any help would be appreciated,
Cru