Tridiro
Board Regular
- Joined
- Apr 26, 2007
- Messages
- 97
Hello Everyone,
I have some code (that I did not write) that will list all of the files in a single directory as hyperlinks in a spreed sheet. I am looking to modify the code so it will include all sub directories (no matter how deep). My plan is to build a User Form to toggle sub directories on and off with a checkbox.
This is not all of the code, but just what is relevant.
Thanks for any help.
I have some code (that I did not write) that will list all of the files in a single directory as hyperlinks in a spreed sheet. I am looking to modify the code so it will include all sub directories (no matter how deep). My plan is to build a User Form to toggle sub directories on and off with a checkbox.
This is not all of the code, but just what is relevant.
Code:
Sub HyperlinkFileList()
'Macro purpose: To create a hyperlinked list of all files in a user
'specified directory, including file size and date last modified
'NOTE: The 'TextToDisplay' property (of the Hyperlink object) was added
'in Excel 2000. This code tests the Excel version and does not use the
'Texttodisplay property if using XL 97.
Dim fso As Object, _
ShellApp As Object, _
File As Object, _
SubFolder As Object, _
Directory As String, _
Problem As Boolean, _
ExcelVer As Integer
'Turn off screen flashing
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'Create objects to get a listing of all files in the directory
Set fso = CreateObject("Scripting.FileSystemObject")
'Prompt user to select a directory
Do
Problem = False
Set ShellApp = CreateObject("Shell.Application"). _
Browseforfolder(0, "Please choose a folder", 0, "c:\\")
On Error Resume Next
'Evaluate if directory is valid
Directory = ShellApp.self.path
Set SubFolder = fso.GetFolder(Directory).Files
If Err.Number <> 0 Then
If MsgBox("You did not choose a valid directory!" & vbCrLf & _
"Would you like to try again?", vbYesNoCancel, _
"Directory Required") <> vbYes Then Exit Sub
Problem = True
End If
On Error GoTo 0
Loop Until Problem = False
Thanks for any help.