View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default UDF that returns a Hyperlink

First, if you mean you want the tooltip to show a different address, then I
don't think that it's possible.

Second, if you meant you want to see something in the cell that isn't the
address of the link, then...

There's an =hyperlink() worksheet function that may do exactly what you want:

=hyperlink("http://www.microsoft.com","Click me!")

Third, If you want to use the Insert|Hyperlink style of hyperlink:

I didn't test this in xl2007, but it seemed to work fine in xl2003:

Option Explicit
Function myHyperLink()

With Application.Caller
.Parent.Hyperlinks.Add Anchor:=.Cells, _
Address:="http://www.microsoft.com"
End With

myHyperLink = "Click me!"
End Function


If you're new to macros:

Debra Dalgleish has some notes how to implement macros he
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

(General, Regular and Standard modules all describe the same thing.)

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:
=myHyperLink()

Vlad wrote:

Is it possible in Excel 2007 using VBA to create a UDF that returns a
hyperlink?

Ideally I want a hyperlink where the display name is different to the
linked URL.

Any ideas?

TIA


--

Dave Peterson