How to lookup hyperlinked cells

  • Thread starter Thread starter neil kempinski
  • Start date Start date
N

neil kempinski

I want to hyperlink several cells to pdf files. Then want to use
lookup function to return a cell and then print both the current wor
sheet and the hyperlinked pdf file.

Can this be done?

thanks
nei
 
Your solution would have to include a UDF (user-defined function) to return
the hyperlink address contained in the cell that has a hyperlink in it. Try
the function below (I have been working on a more sophisticated version for
the Else portion of the clause that will return the URL if the Link argument
is a cell with a HYPERLINK function, but I don't have it fully debugged in
the case of a nested function, etc.).

Public Function HyperlinkURL(Link As Range) As Variant
With Link
If .Hyperlinks.Count > 0 _
Then
'Return the URL of the hyperlink.
HyperlinkURL = .Hyperlinks(1).Address
Else
'Return #N/A! error value if none found.
HyperlinkURL = CVErr(xlErrNA)
End If
End With
End Function

After printing the current worksheet, you would then have to use the Shell
statement to execute a command line similar to the following
"C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe" /p /h "%1" to print
out the PDF file, where "%1" would be replaced by the hyperlink address
returned by the function above.

I am assuming that you have a command button that you want to click to print
out the current worksheet, then fetch the address of the PDF document at the
active cell, then print that out. Technically, you can't do that with a
function. A function can only return a value to a cell, not perform actions
that would be carried out by a command macro.
 

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

Back
Top