Create hyperlink to folder - with a twist maybe

cagni

New Member
Joined
Aug 1, 2022
Messages
24
Office Version
  1. 365
Platform
  1. Windows
Hi

I have this spreadsheet I use to keep track of certain info. With a button it opens a form which then creates a new row and then creates a folder based on value B3 and B8.

What I would like to now is have link created to the folder in the same time as the macro runs? The link should be in B8 where the folder name gets one of its value from. Is this possible?

I´m still learning VBA, so I have had some help with this code.

VBA Code:
Private Sub addProject_Click()

   Dim iRow As Long
   Dim ws As Worksheet
   Set ws = Worksheets("Prewi")

   With ws
      .Range("A8").EntireRow.Insert shift:=xlDown

      With .Range("B8:N8")
         .Borders.Weight = xlThin
         With .Font
            .Size = 11
            .Bold = False
         End With
      End With

      .Range("D8").Value = Date
      .Range("B8").Value = Me.TextBox1.Value
      .Range("C8").Value = Me.TextBox2.Value
      .Range("E8").Value = Me.TextBox3.Value
      .Range("F8").Value = Me.TextBox4.Value
      .Range("L8").Formula = "=(J8-K8)"

      With .Range("G8").Validation
         .Delete
         .Add Type:=xlValidateList, Formula1:="Predicted,In progress,Completed"
         .InCellDropdown = True
      End With
      
      With .Range("H8").Validation
         .Delete
         .Add Type:=xlValidateList, Formula1:="Yes,No"
         .InCellDropdown = True
      End With
      
      With .Range("M8").Validation
         .Delete
         .Add Type:=xlValidateList, Formula1:="Yes,No"
         .InCellDropdown = True
      End With
      
      With .Range("N8").Validation
         .Delete
         .Add Type:=xlValidateList, Formula1:="Yes,No"
         .InCellDropdown = True
      End With
      
      With Worksheets("Prewi").Rows(8)
           .RowHeight = 20
End With

End With

'clear the data
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.TextBox1.SetFocus

    Dim wb As Workbook
    Dim p As String, NwPath As String
    Dim c1 As String, c2 As String
    Dim folder As String

    Set wb = ThisWorkbook
    p = wb.Path & "\"
    Set ws = wb.Sheets("Prewi")
   
    With ws
        c1 = .Range("B3").Value
        c2 = .Range("B8").Value
    End With
   
    NwPath = p & c2 & "_" & c1
    'check if folder exists, if not then create folder
    folder = Dir(NwPath, vbDirectory)
    If folder = vbNullString Then
        VBA.FileSystem.MkDir (NwPath)
    End If

  Unload Me

End Sub

Thank you
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
I am not sure you can just hyperlink a folder
 
Upvote 0
Tell a lie, this approach works

VBA Code:
With Worksheets("WorksheetName")
 .Hyperlinks.Add Anchor:=.Range("where you want the lnk"), _
 Address:="C:\NameOfTheFolder\", _
 ScreenTip:="", _
 TextToDisplay:="NameOfTheFolder"
End With
 
Upvote 0
Solution
Tell a lie, this approach works

VBA Code:
With Worksheets("WorksheetName")
 .Hyperlinks.Add Anchor:=.Range("where you want the lnk"), _
 Address:="C:\NameOfTheFolder\", _
 ScreenTip:="", _
 TextToDisplay:="NameOfTheFolder"
End With
The link should be to same folder as created with the macro. The macro creates a folder where the excel sheet is, so we this macro I have to choose where the link should be before hand?
 
Upvote 0
The link should be to same folder as created with the macro = Address:=NwPath
 
Upvote 0
The link should be to same folder as created with the macro = Address:=NwPath
I have tried with NwPath as the address but I just get "NwPath" as the link. It might just be me as green person in vba :-)
 
Upvote 0
Thank you for the help with this, this works perfekt (y):)

I have another sheet which works almost the same way, except that the path is created from different data. This macro creates a new row, which names B8 with B9+1.

When using you macro in this one, I´m not sure how the "TextToDisplay:="NameOfTheFolder"" should be as this should come from the B8 value which isn´t entered through info box.

VBA Code:
Private Sub addProject_Click()

Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Ark1")

Sheets("Ark1").Range("A8").Select
ActiveCell.EntireRow.Insert shift:=xlDown

Sheets("Ark1").Range("B8:K8").Select
Selection.Borders.Weight = xlThin

Sheets("Ark1").Range("B8:K8").Select
Selection.Font.Size = 11

Sheets("Ark1").Range("B8:K8").Select
Selection.Font.Bold = False

Sheets("Ark1").Range("B8").Select
ActiveCell.Value = Range("B9") + 1

Sheets("Ark1").Range("E8").Select
ActiveCell.Value = Date

With ws
Sheets("Ark1").Range("C8").Select
ActiveCell.Value = Me.TextBox1.Value

Sheets("Ark1").Range("D8").Select
ActiveCell.Value = Me.TextBox2.Value

Sheets("Ark1").Range("F8").Select
ActiveCell.Value = Me.TextBox3.Value

Sheets("Ark1").Range("G8").Select
ActiveCell.Value = Me.TextBox4.Value

Sheets("Ark1").Range("H8").Select
ActiveCell.Value = Me.TextBox5.Value
  
Sheets("Ark1").Range("K8").Select
ActiveCell.Value = Me.TextBox6.Value
End With

'clear the data
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.TextBox5.Value = ""
Me.TextBox6.Value = ""
Me.TextBox1.SetFocus

    Dim wb As Workbook
    Dim p As String, NwPath As String
    Dim c1 As String, c2 As String
    Dim folder As String

    Set wb = ThisWorkbook
    p = wb.Path & "\"
    Set ws = wb.Sheets("Ark1")
    
    With ws
        c1 = .Range("B8").Value
        c2 = .Range("C3").Value
        c3 = .Range("C8").Value
    End With
    
    NwPath = p & c1 & "_" & c2 & "_" & c3
    'check if folder exists, if not then create folder
    folder = Dir(NwPath, vbDirectory)
    If folder = vbNullString Then
        VBA.FileSystem.MkDir (NwPath)
    End If

  Unload Me
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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