Hyperlink to open pdf in same directory

acowl

New Member
Joined
Jan 19, 2018
Messages
8
I have a spreadsheet "Contracts.xls" and I would like to be able to open PDFs via a hyperlinked cell on each row. The PDFs are stored in the same directory as the spreadsheet. For example, for contract 0001 I have a pdf in the same directory named 0001.pdf.

The path to the directory will change for each user in my organisation, so I don't want to use the full file path to open the PDFs. I would like the hyperlink to only take into account the folder that the spreadsheet is stored in.

Thanks!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
On Google Drive. Therefore the filepath for each user will be different (something like Users>Company Name>User>Google Drive>Contracts) for example, with each 'User' being different.
 
Upvote 0
Perhaps something like this

Code:
    Dim strPath As String
    strPath = Environ("HomeDrive") & Environ("HomePath") & "\Desktop\" 
'Change where the folder is located i.e "\Documents\Company\Contracts\"
'Your Code....
End Sub
 
Last edited:
Upvote 0
Ah, I don't even know where to start understanding something like that I'm afraid. I was hoping a formula would do the trick. I know it used to be quite simple to do in older versions of Excel using formulas and I hoped the method had just changed. I was hoping a variation of something like this would work: https://stackoverflow.com/questions...erlink-to-file-in-same-directory-as-xlsx-file

Is it definitely impossible to do without code?
 
Upvote 0
It probably is possible but formula is not my strong suit, However give this a go....

Code:
Sub GetDoc()
Dim strPath As String
Dim MyValue As Variant
    Application.ScreenUpdating = False
        Selection.NumberFormat = "@"
        MyValue = InputBox("Enter Contract Document Number", "Contracts")
        If MyValue = "" Then
        MsgBox "HyperLink not created!"
    Exit Sub
    End If
        strPath = Environ("HomeDrive") & Environ("HomePath") & "\Desktop\Contracts\" ' Change As Required
        ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=strPath, TextToDisplay:=MyValue
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,193
Members
452,616
Latest member
intern444

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