Find the row for a Hyperlink

C

cubbybear3

I have a web query that imports a table with both text and
hyperlinks. What I need is the row number of each cell that has a
hyperlink and the URL for it.

I know how to read the cells that I want using: For Each rangeX In
Sheets("x").Range("A1:G7")
but I can not figure out how to determine the cells that have
hyperlinks.

I can also read the page using the following: For Each hyperX In
Sheets("x").Hyperlinks
but I can not figure out how to determine the worksheet row/col of the
hyperlink.

Any suggestions? (using WinXP and both XL2003 & XL2007)
 
R

Ron Rosenfeld

I have a web query that imports a table with both text and
hyperlinks. What I need is the row number of each cell that has a
hyperlink and the URL for it.

I know how to read the cells that I want using: For Each rangeX In
Sheets("x").Range("A1:G7")
but I can not figure out how to determine the cells that have
hyperlinks.

I can also read the page using the following: For Each hyperX In
Sheets("x").Hyperlinks
but I can not figure out how to determine the worksheet row/col of the
hyperlink.

Any suggestions? (using WinXP and both XL2003 & XL2007)

In xl2007 (I don't know about xl2003), you can get the row from

hyperX.range.row

and the column from

hyperX.range.column.


To get the cell address:

======================
Option Explicit
Sub GetHyperlinkAddress()
Dim hls As Hyperlinks, hl As Hyperlink
Dim v()
Set hls = Worksheets("sheet1").Hyperlinks
For Each hl In hls
Debug.Print hl.Name, Cells(hl.Range.Row, hl.Range.Column).Address
Next hl
End Sub
============================

If you put a breakpoint at "next hl" and add a watch for hl, you can discern all types of interesting information from the watch window.
 
R

Ron Rosenfeld

I have a web query that imports a table with both text and
hyperlinks. What I need is the row number of each cell that has a
hyperlink and the URL for it.

I know how to read the cells that I want using: For Each rangeX In
Sheets("x").Range("A1:G7")
but I can not figure out how to determine the cells that have
hyperlinks.

I can also read the page using the following: For Each hyperX In
Sheets("x").Hyperlinks
but I can not figure out how to determine the worksheet row/col of the
hyperlink.

Any suggestions? (using WinXP and both XL2003 & XL2007)

Of course, to get just the address that the hyperlink is attached to, you can more simply use:

hl.range.address

Also see HELP for the members of the hyperlink object.
 
C

cubbybear3

Thanks Ron,

Is there any way to identify the Hyperlink using the 1st method
(For Each rangeX In Sheets("x").Range("A1:G7")?

-pb
 
R

Ron Rosenfeld

Thanks Ron,

Is there any way to identify the Hyperlink using the 1st method
(For Each rangeX In Sheets("x").Range("A1:G7")?

-pb


For Each rangeX in ...
If rangeX.Hyperlinks.Count > 0 Then
Debug.Print rangeX.Address, rangeX.Hyperlinks(1).Address
End If
next rangeX
 

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