VBA to create a list of subfolder names and hyperlink to those folders?

Joined
Jun 28, 2021
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone.

I have a parent folder with about 50 subfolders. I'm looking for a way to create a list in Excel of the names of those 50 subfolders (not the names of the files inside the subfolders) with hyperlinks to those subfolders.

Any help would be highly appreciated.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hope this helps.

VBA Code:
Sub Sample()
    Dim buf As String, cnt As Long
    Dim path As String
    path = "C:\Users\"
    cnt = 1
    buf = Dir(path, vbDirectory)
    Do While buf <> ""
        If InStr(buf, ".") = 0 Then
            Cells(cnt, 1).Value = buf
            ActiveSheet.Hyperlinks.Add Anchor:=Cells(cnt, 1), Address:=path & buf
            cnt = cnt + 1
        End If
        buf = Dir()
    Loop
End Sub
 
Upvote 0
Solution
Hope this helps.

VBA Code:
Sub Sample()
    Dim buf As String, cnt As Long
    Dim path As String
    path = "C:\Users\"
    cnt = 1
    buf = Dir(path, vbDirectory)
    Do While buf <> ""
        If InStr(buf, ".") = 0 Then
            Cells(cnt, 1).Value = buf
            ActiveSheet.Hyperlinks.Add Anchor:=Cells(cnt, 1), Address:=path & buf
            cnt = cnt + 1
        End If
        buf = Dir()
    Loop
End Sub
That worked perfectly. Many thanks!
 
Upvote 0

Forum statistics

Threads
1,214,620
Messages
6,120,559
Members
448,970
Latest member
kennimack

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