VBA Return Hyperlink Function


New Member
Jun 10, 2009
I'm having a problem writing a VBA function. I want to call a function that looks something like this... GetLink("CCF-2000",K18) where the CCF-2000 is a project folder on my computer and K18 references a code related to the city. Using K18 and the Case function I'll differentiate between different file paths related to different cities.

Anyways, I got the Case function to work properly, but when I try to run the Excel Hyperlink function in VBA it returns #VALUE. I want it to return something simliar to =HYPERLINK("G:\CCF-2000", "CCF-2000"), but using a function to figure out the path based on the city code.

The K column only contains data such as SG, SP, LE, ENW, etc... that specify a city. Each city has it's own path on the local computer.

Here's the function I was trying to build to accomplish this. I wanted to call this function in another column... AC, to return a hyperlink, but to no avail.

Function GetLink(Filename as String, City as String) as String

Select Case City
Case "ENW", "ENE", "ESW", "ESE"
GetLink = Application.WorksheetFunctions.Hyperlink("G:\" & Filename, Filename)
Case "SG"
GetLink = Application.WorksheetFunctions.Hyperlink("G:\SG\" & Filename, Filename)
Case Else
GetLink = "Escape"
End Select
Hopefully, there's something in there that makes sense. It's my first VBA function, so hopefully that's not too far from the truth.

Some videos you may like

Excel Facts

Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Latest member

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...