How can I pass an array as TextToDisplay to a hyperlink?

J

Jay Fincannon

I have a procedure that searches through every sheet (108) in a
workbook for matching data then puts a hyperlink to those data onto a
"Hyperlog" worksheet.

here's part of the code
Option Explicit
Option Base 1

Dim hlText(3) as String
Dim rte as string
Dim num as string
Dim street as string
Dim r as Integer
Dim foundNum as Range
..
..
..
r = 3
hlTarget:=foundNum 'result of Find"
a do loop here as long as matches are being found

hlText(1) = rte: hlText(2) = num: hlText(3) = street

Sheets("HyperLog").Hyperlinks.Add Anchor:=Cells(r, 1), _
Address:="", SubAddress:=rte & "!" & hlTarget, TextToDisplay:=hlText()

If I use hlText() or hlText, I get invalid argument error.
If I use hlText(3) only the 3rd element is passed
hlText(1) & hlText(2) & hlText(3) works except when executing the
hyperlink

Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal
Target As Hyperlink)
CenterOnCell Range Target.SubAddress, Target.TextToDisplay
End Sub
fails at .TextToDisplay
What do I do now coach?

Jay
 
T

Tom Ogilvy

What do you mean fails? What is the error message? What is the declaration
for CenterOnCell?
 
J

Jay Fincannon

Error message

Compile error:
Type mismatch: array or user-defined type expected


CenterOnCell(OnCell as Range, Street() as String)
 
T

Tom Ogilvy

If you do this:

Sheets("HyperLog").Hyperlinks.Add Anchor:=Cells(r, 1), _
Address:="", SubAddress:=rte & "!" & _
hlTarget, TextToDisplay:=hlText(1) & hlText(2) & hlText(3)

then
you must declare CenterOnCell as
CenterOnCell(OnCell as Range, Street as String)

and process Street as a string, not an array.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top