Excel Macro to include hyperlink to where file is saved

texasguy66

New Member
Joined
May 31, 2023
Messages
16
Office Version
  1. 365
Platform
  1. Windows
Hello everyone.

I have an excel spreadsheet and have a tab that generates an email of the information. Would like to include a link in the spreadsheet to where the file is saved at (on a network drive). The folders change frequently so I am unable to have a fixed location. How could I achieve this?

Thanks in advance.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
you haven't said where on the worksheet you want the link or what the workhseet is called so I assume A1 and "emailtab" adjust as necessary:
VBA Code:
Sub test()

tt = ActiveWorkbook.Path
     With Worksheets("emailtab")
      .Hyperlinks.Add Anchor:=.Range("a1"), _
                        Address:=tt, _
                        TextToDisplay:=tt
      End With

End Sub
 
Upvote 0
Thanks, it works great.

Is there a way to show the hyperlink as the word "link" versus it showing the file path?
 
Upvote 0
yes very easily:
VBA Code:
tt = ActiveWorkbook.Path
     With Worksheets("emailtab")
      .Hyperlinks.Add Anchor:=.Range("a1"), _
                        Address:=tt, _
                        TextToDisplay:="Link"
      End With
 
Upvote 0

Forum statistics

Threads
1,215,151
Messages
6,123,316
Members
449,094
Latest member
Chestertim

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