Macro List Files and Hyperlink

Blueridge227

New Member
Joined
Mar 23, 2011
Messages
29
I'm looking for a solution that will allow me to list all files in a directory including ones in sub folders and then hyperlink them.

Also if its possible, I would like to show the folder name in column A and the Filename in Column B.

Any help is greatly appreciated!
thank you in advance!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Try:
Code:
Dim fso As Variant
Dim r As Long, dst As Worksheet
Sub test()
    r = 2
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set dst = ActiveSheet
    Application.ScreenUpdating = False
    With dst.Range("A1:C1")
        .Value = Array("FOLDER", "FILE", "LINK")
        .Font.Bold = True
    End With
    writeData "C:\LOCAL\"
    dst.Range("A:C").EntireColumn.AutoFit
    Set fso = Nothing
End Sub
Sub writeData(path)
    Set fld = fso.GetFolder(path)
    With dst
        If fld.Files.Count > 0 Then
            For Each file In fld.Files
                .Cells(r, 1).Value = path
                .Cells(r, 2).Value = Mid(file, InStrRev(file, "\") + 1, 255)
                .Cells(r, 3).FormulaR1C1 = "=HYPERLINK(RC[-2]&""\""&RC[-1],""Open"")"
                r = r + 1
            Next
        End If
        If fld.subfolders.Count > 0 Then
            For Each folder In fld.subfolders
                writeData folder
            Next
        End If
    End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,159
Members
452,892
Latest member
yadavagiri

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top