UPDATE: due to Karls comment, I revised my answer, found out that Excel 2007 does not seem to allow user-defined functions to set hyperlinks anymore (quite reasonably, see my own comment in the code). Thus, the source code (below the line) does not work in later versions of Excel (I have not tested Excel 2010, but I assume that the result is the same). For historical reasons, I do not delete the old code (the editor may think differently - feel free to edit / delete accordingly).
So it remains to set long hyperlinks programmatically, for example
Sub insertVeryLongHyperlink() Dim curCell As Range Dim longHyperlink As String Set curCell = Range("A1") ' or use any cell-reference longHyperlink = "http://www.veryLongURL.com/abcde" ' Or a Cell reference like [C1] curCell.Hyperlinks.Add Anchor:=curCell, _ Address:=longHyperlink, _ SubAddress:="", _ ScreenTip:=" - Click here to follow the hyperlink", _ TextToDisplay:="Long Hyperlink" End Sub
What further does not work in Excel 2010; see my comment above
"Copy the hyperlink from Word and paste into Excel" made me think. Obviously, the limit is both in the built-in HYPERLINK function and in the "edit hyperlink" dialog box. On the other hand, it should be - and in fact - it is possible to set longer hyperlinks through VBA.
This code no longer works in Excel 2010
Function myHyperlink(cell As Range, _ hyperlinkAddress As String, _ Optional TextToDisplay As Variant, _ Optional ScreenTip As Variant) ' Inserts a Hyperlink ' at the position cell (this should be the position where the UDF is used, ' since the return value of the UDF is = TextToDisplay) ' with the hyperlinkAddress ' optional TextToDisplay ' optional ScreenTip ' ####################################### ' Warning Warning Warning Warning Warning ' ####################################### ' 1) Since it is really bad practice to have a function perform procedural ' tasks, you should not do this. ' 2) You have no garantee, the link is updated when the value hyperlinkAddress changes ' USE AT YOUR ONE RISK AND ONLY IN CASE OF EMERGENCIES :-) ' If more than one cell is selected as target range, ' use the top left cell Set cell = cell.Resize(1, 1) If IsMissing(TextToDisplay) Then TextToDisplay = hyperlinkAddress End If If IsMissing(ScreenTip) Then ScreenTip = hyperlinkAddress & " - Click here to follow the hyperlink" End If cell.Hyperlinks.Add Anchor:=ActiveCell, _ Address:=hyperlinkAddress, _ SubAddress:="", _ ScreenTip:=ScreenTip, _ TextToDisplay:=TextToDisplay ' There doesn't seem to be another way to set TextToDisplay myHyperlink = TextToDisplay End Function
Use as a regular Excel function, but be sure to add the current cell as the first parameter (i.e. the following formula is inserted in cell A1)
=myHyperlink(A1,B1) =myHyperlink(A1,B1,"TextToDisplay", "ScreenTip")
You can neither drag the formula, nor copy it to another cell. If you do this, you will have to recalculate the formula (neither ALT-CTRL-F9 nor ALT-CTRL-SHIFT-F9 work as a force recalculation), so go to each cell, press F2 to activate it and end with Return .
I hope I do not help you mess up too many Excel workbooks.
It is probably safer to write a VBA that is explicitly running, iterating through the list and writing to hyperlinks. Thus, they can be reused, but no functions.
Relations Andreas