HyperLinks to folders with the same name as excel cell value

timofey

New Member
Joined
Apr 4, 2023
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi MrExcel community, this is my first time for posting here. Though I know the topic about matching(look up) and hyperlinks in VBA Excel has been repeated a lot. I have a macros that I would love to ask on how to code which I will explain the criteria of it down below with a picture for better visual explanation.
1. I have for example 300 casecodes from work in column A
2. I have exact same number of folders with name of these case codes.
3. I need to create hyperlinks to this folders which are on my computer.
Is it even possible? I found a way to create folders path with VBA and then with HyperLink formula create a link but this is too complex for me.
Hope you will help me ^^
 

Attachments

  • 1234.png
    1234.png
    79.1 KB · Views: 58

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Also i found this vbacode but it wont work for me. No bugs in code from troubleshooter but links are not creating only deleting old ones.
VBA Code:
Sub SetLink()
Dim dir as String
Dim r as Range, c as Range
Dim FolderExists as Boolean

application.screenupdating = false 'turns off screen updating for speed

Set R = Range("A:A").SpecialCells(xlCellTypeConstants) 'this will select all cells in column A that have a value
ActiveSheet.Hyperlinks.Delete 'clears all hyperlinks... we're just going to add them back later...

For each c in R  'loops through all those cells one by one
 dir = "C:\Yourpathhere\" & c.Value  'change this to the path that houses your case number folders
 On Error Resume Next
   FolderExists = (GetAttr(dir) And vbDirectory) = vbDirectory
 On Error GoTo 0

 If FolderExists Then
   ActiveSheet.Hyperlinks.Add Anchor:=c.Offset(,1), Address:=dir
 End If
Next c


application.screenupdating = true 'turns screen updating back on.

End Sub
 
Last edited by a moderator:
Upvote 0
Try this macro. It expects the subfolder names to be on the active sheet in column A starting at A2. You must edit the code to change the Main_Folder string, which is the main folder containing all the subfolders.
VBA Code:
Public Sub Create_Links_To_Folders()

    Dim cell As Range
    
    Const Main_Folder  As String = "C:\path\to\main\folder\"     'CHANGE THIS
    
    'Create hyperlinks in column A for each cell in column A starting at A2
    
    With ActiveSheet
        For Each cell In .Range("A2", .Cells(.Rows.Count, "A").End(xlUp))
            .Hyperlinks.Add Anchor:=cell, Address:=Main_Folder & cell.Value
        Next
    End With
    
End Sub
 
Upvote 1
Solution
Try this macro. It expects the subfolder names to be on the active sheet in column A starting at A2. You must edit the code to change the Main_Folder string, which is the main folder containing all the subfolders.
VBA Code:
Public Sub Create_Links_To_Folders()

    Dim cell As Range
   
    Const Main_Folder  As String = "C:\path\to\main\folder\"     'CHANGE THIS
   
    'Create hyperlinks in column A for each cell in column A starting at A2
   
    With ActiveSheet
        For Each cell In .Range("A2", .Cells(.Rows.Count, "A").End(xlUp))
            .Hyperlinks.Add Anchor:=cell, Address:=Main_Folder & cell.Value
        Next
    End With
   
End Sub
Awesome it works, links was created but new problem appeared
 

Attachments

  • 4123.png
    4123.png
    17.1 KB · Views: 55
Upvote 0

Forum statistics

Threads
1,223,881
Messages
6,175,161
Members
452,615
Latest member
bogeys2birdies

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