Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Hyperlinks Issue

Status
Not open for further replies.

MarH

Vendor
Nov 1, 2007
4
GB
Hi All,

I think that this is a simple problem but just cant see the answer...

I am generating code within a worksheet (index) that produces hyperlinks to other cells in another worksheet (Questions) that are in the same workbook.

I have generated the code below, but when the hyperlink is clicked nothing happens!

I hover over the hyperlink and get the addres file:///filepath-filename-$x$xx

- I dont get the worksheet reference shown in the hyperlink??


I think that it is an issues with the Address property as it returns the cells in string format but I really am unsure about this!

strLink = Worksheets("Questions").Cells(ValRow, 4)
Worksheets("Index").Hyperlinks.Add Anchor:=Cells(ValRowCount, 3), Address:="", _
SubAddress:=Worksheets("Questions").Cells(ValRowCount, 3).Address, TextToDisplay:=strLink

Help Please !!!
 
the issue is your anchor and your subaddress are the same thing:

Anchor:=Cells(ValRowCount, 3)
SubAddress:=Worksheets("Questions").Cells(ValRowCount, 3)

The address of a range does not take into acount the sheet name so the address you are giving the hyperlink will be the same as the address it is sat on - hence no movement.

Try this:
Code:
Worksheets("Index").Hyperlinks.Add Anchor:=Cells(ValRowCount, 3), Address:="", _
     SubAddress:="Questions!" & Cells(ValRowCount, 3).Address, TextToDisplay:=strLink



Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Thanks Geoff,

I see what is now the obvious mistake! DOH!!!

M
 
Yea I forget all the time - workbooks, sheets, (active or specific) and forms have to be referenced as well as the object in VBA and not all commands use the same syntax.
Sometimes Activesheet.cells(etc) ,
sometimes Sheets("fred").text etc only does it.
I am sure there is a logic but it changes in Word VBA again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top