Create a Hyperlink without knowing the full folder name

kgkev

Well-known Member
Joined
Jun 24, 2008
Messages
1,285
Office Version
  1. 365
Platform
  1. Windows
I would like to open a folder from a hyperlink in a cell.

The folder is situated in
\\IH-FS\Data\Production\Safety\A7 COSHH SHEETS & SDS\

Cell B1:B200 contain the start of the folder name

B2 = "COSHH ASSESSMENT 0001"
B3 = "COSHH ASSESSMENT 0002"

However, the actual folders include the name of the product/chemical on the data sheet.

"COSHH ASSESSMENT 0001 - PROPANE"
"COSHH ASSESSMENT 0002 - LOCTITE 603"

is it possible to use a wild card to still open the folder without knowing the actual folder name?

I have tried...and failed with

Excel Formula:
=HYPERLINK("\\IH-FS\Data\Production\Safety\A7 COSHH SHEETS & SDS\"&B2&"*","LINK")

Any help would be appreciated.
I could rename all the folders to remove the product name, but we still need to be able to access the folders directly as well.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
you could write a function in VBA to get the full directory name, and then use that to create the hyperlink.

VBA Code:
Option Explicit

Function GetSubDirectory(sParentDir As String, sStartDirName As String) As String
    Dim FSO As Object
    Dim objFolder As Object
    Dim objSubFolder As Object
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = FSO.GetFolder(sParentDir)
    
    For Each objSubFolder In objFolder.SubFolders
        If LCase(objSubFolder.Name) Like LCase(sStartDirName) & "*" Then
            GetSubDirectory = objSubFolder.Name
            Exit For
        End If
    Next objSubFolder
    
End Function

In a cell enter:
Excel Formula:
=GetSubDirectory("\\IH-FS\Data\Production\Safety\A7 COSHH SHEETS & SDS\",B2)

and it will give you the full path.
you can use that in your hyperlinnk
 
Upvote 0

Forum statistics

Threads
1,215,409
Messages
6,124,743
Members
449,186
Latest member
HBryant

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