PDA

View Full Version : Hyperlinks from Range



MWE
02-26-2006, 05:50 PM
Please excuse the messy text; the forum has been upgraded (or is it downgraded?) and it is quite a mess. I will use || as a paragraph marker so you can do manual separation.


I am running Word2000. I am trying to add a hyperlink to a particular cell in each row of a table. I would post the VBA text, but it would be a mess given the problems with the forum, e.g., VBA tags are not working, paragraphing is not working, etc.

VBA help for hyperlinks from ranges states



expression.Add(Anchor, Address, SubAddress, ScreenTip, TextToDisplay, Target) and
Anchor: Required Object. The text or graphic that you want turned into a hyperlink.

So I am using


With Table.Cell(Row:=#, Col:=#)
' other VBA
.Range.Hyperlinks.add .range, address
End With


I think I am appropriately using the cells Range as the anchor (I want the original cell text to be the anchor) and the appropriate Address as the target address. The resulting table entry is not what I want. The cells range is expanded to include the target address. That extra text is the text to which the actual hyperlink is "attached". The hyperlink from that added text is correct, i.e., it links to the correct location.

|| So, what am I doing wrong?

Edited by XLGibbs to paragraph and add VBA tags. No original content was removed.

XLGibbs
02-26-2006, 06:08 PM
Try

.Range.Hyperlink.Add .range,address,,,.range


This code works in excel, and does not work properly if each argument is not supplied (for me, but I don't preface it with Address:= , or anchor:=)


With c.Hyperlinks
If .Count = 0 Then
.Add c, "www.vbaexpress.com", , , c.Text
Else
.Delete
.Add c, "www.vbaexpress.com", , , c.Text
End If
End With


where Range c is the anchor, and c.text is the displayed text.

XLGibbs
02-26-2006, 06:08 PM
By supplied I mean, noted by the , in the syntax...

MWE
02-27-2006, 08:37 PM
Try



VBA:

.Range.Hyperlink.Add .range,address,,,.range

VBA tags courtesy of www.thecodenet.com (http://www.thecodenet.com)


This code works in excel, and does not work properly if each argument is not supplied (for me, but I don't preface it with Address:= , or anchor:=)




VBA:

With c.Hyperlinks If .Count = 0 Then .Add c, "www.vbaexpress.com", , , c.Text Else .Delete .Add c, "www.vbaexpress.com", , , c.Text End If End With

VBA tags courtesy of www.thecodenet.com (http://www.thecodenet.com)


where Range c is the anchor, and c.text is the displayed text. In the Reply To Thread window, the above quote is a mess of html tags, but it seems to display at the next level up OK ??? Whatever, thanks for the reply. I was able to get it working. The key was to use a null .range as the anchor, define the address normally, then use .range as the TextToDisplay, and then do any final formatting on the cells contents.