Include cell text in web hyperlink?

D

Doug

I have a hyperlink to a web database. Up till now I have been clicking on the
hyperlink and once it takes me to that web page I then include a cell
reference from excel at the end of the web address to obtain the data that I
need. What I am hoping is that I can have excel somehow include or attach
the text in the cell to the end of the hyperlink when I click on the cell.
This would be very helpful. Is this possible?
 
J

Joel

If I rretrhad the URL I can write some code. The best solution would be to
have a control button which you can activate. The control button can open an
internet explorer application which can automatically retreve the data from
the URL and place the data into you worksheet.

If the URL is not public then I can send you some examples of code that
would perform the task. Working with the internet explorer application is a
litle tricky b eause every webpage is different. Knowing html will help.
 
J

Joel

Put your stock names on Sheet1 starting in cell A2 and going down each row.
The code will put the Header Row on the sheet and put in all the stock info.
The macro stops when it finds a empty cells in column A after row 2. You can
add a control button to your worksheet to run the macro. I tested the code
with a few different stocks.

the macro runs fine wwhen the webpage is not active (like 6:00 AM). Started
to get slow and timout around 7:30 AM. If the code fails try it again.



Sub GetStock2()

URLLOOKUP = "http://www.schaeffersresearch.com/streetools/" & _
"stock_quotes.aspx?Ticker="
NoResults = "There are no"

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

First = True
With Sheets("Sheet1")
StockRow = 2
Do While .Range("A" & StockRow) <> ""
StockName = .Range("A" & StockRow)

URL = URLLOOKUP & StockName
'get web page
IE.Navigate2 URL
Do While IE.readyState <> 4 Or IE.Busy = True
DoEvents
Loop

Set Tables = IE.document.getElementsByTagName("Table")
ColCount = 2
For TableCount = 1 To 4
Set Table = Tables(TableCount)
For Each MyRow In Table.Rows
Count = 1
For Each Itm In MyRow.Cells
If Count = 1 Then
If First = True Then
.Cells(1, ColCount) = Itm.innertext
End If
Else
.Cells(StockRow, ColCount) = Itm.innertext
End If
Count = Count + 1
Next Itm
ColCount = ColCount + 1
Next MyRow
Next TableCount
First = False

StockRow = StockRow + 1
Loop
End With

IE.Quit

End Sub
 
D

Don Guillett

Right click sheet tab>view code>insert this>then enter ge or ibm or t into
any cell in col M

Private Sub Worksheet_Change(ByVal target As Range)
If target.Column <> 13 Then Exit Sub
ActiveWorkbook.FollowHyperlink Address:= _
"http://www.schaeffersresearch.com/streetools/" & _
"stock_quotes.aspx?Ticker=" & target.Value & ""
End Sub
 
J

Joel

Don: Your code just goes to the webpage and doesn't return any values. Try
my code and you will see the differences.
 
J

Joel

Don:L doug said "to obtain the data that I need". I wasn't sure what he
meant so I downloaded all the data. Doug asked for the links but I assumed
he really wanted to automatically get all the data.
 
D

Don Guillett

And of course you could always set up a refresh of an external query tied to
a worksheet_change event or a looping macro. May not want all 4 tables?

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> Range("a1").Address Then Exit Sub
With ActiveSheet.QueryTables(1)
.Connection = _
"URL;http://www.schaeffersresearch.com" & _
"/streetools/stock_quotes.aspx?Ticker=" & Range("a1")
.Refresh BackgroundQuery:=False
End With
End Sub
Last 23.44
High 23.53
Prev Close 23.44
52Wk Low 20.9

Change
Low 23.39
Dividend Date 7/8/2009
EPS 2.12

% Change 0.00%
Volume 1,644,898
Dividend Amount 1.64
Shares Out 5,900,000,000

Open 23.53
52Wk High 33.56
P/E Ratio 11.6
Yield 6.7
 
J

Joel

that code will only work for 1 stock and only when you change the company
name. It will not work when there are multiple stocks on the same sheet.
The problem is with queries is the connection property cannot be changed once
the query is initiated. You have only on querytable in your code.
 
D

Don Guillett

As I said, this could be set up with a looping macro on the one query to do
the fetch>copy the desired data to where ever is necessary>do the same for
the next symbol. Even better when a .csv where you can bring in all symbols
(Yahoo allows 200 at at time and you can also loop that for an infinite
number) with ONLY ONE fetch. and then do TTC to separate.

With Sheets(2).QueryTables.Add(Connection:="URL;" _
& "http://download.finance.yahoo.com/d/quotes.csv?s=" & _
symbols & "&f=snd1t1l1ohgpvqyd&e=.csv", _
Destination:=Sheets("Data").Cells(dr, dc))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = True
End With

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
Joel said:
that code will only work for 1 stock and only when you change the company
name. It will not work when there are multiple stocks on the same sheet.
The problem is with queries is the connection property cannot be changed
once
the query is initiated. You have only on querytable in your code.
 
D

Doug

Don, this works good except you have to click in the formula bar each time in
order to select another cell. Also is there a way to designate it to the "M"
column only? Every time I try to enter data in another column it tries to
take me to the hyperlink. Really appreciate your help...
 
D

Don Guillett

This was restricted to column 13. Did you put in the SHEET module as
instructed?
If desired, send your file to my address below along with this msg and
a clear explanation of what you want and before/after examples.
 
D

Doug

Say Don! Do you know if there is a way to highlight a selected row without
overidding the the hyperlink formula you gave me for selected cells.

In the earlier formula, if I double click on a selected range it takes me to
those hyperlinks. If I could, I would also like to be able to click once on a
cell in that row and have it outline that row so that I can easily view the
pertaining data?
--
Appreciate your help


Don Guillett said:
I changed to a double_click event
 

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