View Single Post
  #3   Report Post  
Gord Dibben
 
Posts: n/a
Default

Dave

This UDF returns nothing when hyperlink is to a second sheet in same workbook.

Any way to alter?

Gord Dibben Excel MVP

On Sun, 31 Oct 2004 17:56:40 -0600, Dave Peterson wrote:

One way to extract those URL's from a hyperlink created via Insert|Hyperlink
is with a userdefinedfunction.

Here's one that may help:

Option Explicit
Function GetURL(Rng As Range) As String
Application.Volatile

Set Rng = Rng(1)

If Rng.Hyperlinks.Count = 0 Then
GetURL = ""
Else
GetURL = Rng.Hyperlinks(1).Address
End If
End Function

So if you had a hyperlink in A1, you could put =getURL(a1) in that adjacent
cell.

Be aware that if you change the hyperlink, then this formula cell won't change
until your workbook calculates.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:

Open your workbook.
Hit alt-f11 to get to the VBE (where macros/UDF's live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like: VBAProject (yourfilename.xls)

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand side

Paste the code in there.

Now go back to excel.
Into a test cell and type:
=getURL(a1)

Poon Xiulok wrote:

Is there a worksheet function that returns the contents of a hyperlink? For
instance, the content of cell A1 is "something" which contains a hyperlink
to "somewhere". How can I show "somewhere" in B1?