adjusting code "Fluff" hyperlink subfolder to open

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hello
i got this code from mr.Fluff i would thank him if is possible to add to code and make it link hyperlink every subfolder to open it
VBA Code:
Sub abdelfattah()
   Dim Fldr As String
   Dim SubFldr As Object
   Dim i As Long
 
   i = 2
   With Application.FileDialog(4)
      .AllowMultiSelect = False
      If .Show = -1 Then Fldr = .SelectedItems(1)
   End With
   With CreateObject("scripting.filesystemobject")
      For Each SubFldr In .GetFolder(Fldr).SubFolders
         Cells(i, 3) = SubFldr.Name
         i = i + 1
      Next
   End With
End Sub
thanks
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Try:
VBA Code:
Sub abdelfattah()
   Dim Fldr As String
   Dim SubFldr As Object
   Dim i As Long
 
   i = 2
   With Application.FileDialog(4)
      .AllowMultiSelect = False
      If .Show = -1 Then Fldr = .SelectedItems(1)
   End With
   With CreateObject("scripting.filesystemobject")
      For Each SubFldr In .GetFolder(Fldr).SubFolders
         ActiveSheet.Hyperlinks.Add Anchor:=Cells(i, 3), _
                Address:=Fldr & Application.PathSeparator & SubFldr.Name, _
                TextToDisplay:=SubFldr.Name
         i = i + 1
      Next
   End With
End Sub
 
Upvote 0
hi, Misca i try overcome error if i don't choose folder from browser and press cancel it gives me error in this line
VBA Code:
      For Each SubFldr In .GetFolder(Fldr).SubFolders
i try putting this line before it but it not successful
Code:
On Error Resume Next
any idea,please?
 
Upvote 0
You can solve this by adding a line that checks if the Fldr is empty:
VBA Code:
Sub abdelfattah()
   Dim Fldr As String
   Dim SubFldr As Object
   Dim i As Long
 
   i = 2
   With Application.FileDialog(4)
      .AllowMultiSelect = False
      If .Show = -1 Then Fldr = .SelectedItems(1)
   End With
   
  [B] If Fldr <> "" Then[/B]
   
    With CreateObject("scripting.filesystemobject")
       For Each SubFldr In .GetFolder(Fldr).SubFolders
          ActiveSheet.Hyperlinks.Add Anchor:=Cells(i, 3), _
                 Address:=Fldr & Application.PathSeparator & SubFldr.Name, _
                 TextToDisplay:=SubFldr.Name
          i = i + 1
       Next
    End With
   
   [B]End If[/B]
   
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,947
Messages
6,122,413
Members
449,082
Latest member
tish101

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