Hi - I'm very new to Excel VBA and I'm trying to learn some useful new things. I need to pull a certain table (I really don't want all of it, but I can delete columns later) from a webpage and then have it show up in Excel. I would really like to make it part of a macro. I tried creating a query using "from web" on the data tab, but it won't go because the table isn't easily identifiable. I thought I had the found an example of the code online, but I can't get it to work.
Website with table: Price % Losers - Yahoo! Finance
Here's what I'm hoping to have at the end:
<tbody>
</tbody>Here's the code I have so far:
However it doesn't do anything. I changed the url and the table id from the original, but it doesn't work. Any thoughts or help would be appreciated! Thanks!
Website with table: Price % Losers - Yahoo! Finance
Here's what I'm hoping to have at the end:
Symbol | Name | Change (dollars) | Change (%) | Volume |
CBMXW | CombiMatrix Corporation | 0.32 | -29.44% | 3,371 |
BIOA-WT | BIOAMBER INC. | 0.53 | -23.13% | 10,070 |
AFOP | Alliance Fiber Optic Products, | 3.48 | -22.40% | 4,046,002 |
SIEB | Siebert Financial Corp. | 0.79 | -20.52% | 115,812 |
MICTW | Micronet Enertec Technologies, | 0.28 | -20.16% | 7,574 |
KONE | Kingtone Wirelessinfo Solution | 1.91 | -19.02% | 55,635 |
PSMI | Peregrine Semiconductor Corp. | 1.07 | -16.09% | 1,859,531 |
SPRO | SmartPros Ltd. | 0.32 | -13.33% | 30,710 |
STLY | Stanley Furniture Company, Inc. | 0.49 | -13.10% | 165,090 |
PFH | Cabco Tr Jcp 7.625 Common Stock | 1.89 | -11.52% | 34,268 |
PCYG | Park City Group, Inc. | 0.93 | -10.78% | 1,375,707 |
SSY | SunLink Health Systems, Inc. Co | 0.13 | -10.74% | 191,634 |
JCP | J.C. Penney Company, Inc. Holdi | 0.6 | -10.56% | 111,996,561 |
CPAH | CounterPath Corporation | 0.13 | -10.56% | 48,695 |
DNB | Dun & Bradstreet Corporation (T | 10.88 | -10.22% | 2,803,022 |
KBIO | KaloBios Pharmaceuticals, Inc. | 0.29 | -10.00% | 2,837,149 |
TTWO | Take-Two Interactive Software, | 1.84 | -9.74% | 21,554,877 |
ORMP | Oramed Pharmaceuticals Inc. | 1.59 | -9.48% | 1,626,089 |
VSCI | Vision-Sciences, Inc. | 0.13 | -9.29% | 174,669 |
<tbody>
</tbody>
Code:
Sub GetTableFromWebsite()
Sheets("Website Table Test").Select
Range("A1").Select
Dim x As Long, y As Long
Dim htm As Object
Set htm = CreateObject("htmlFile")
With CreateObject("msxml2.xmlhttp")
.Open "GET", "http://finance.yahoo.com/losers?e=us", False
.send
htm.body.innerhtml = .responsetext
End With
With htm.getelementbyid("yfsbar")
For x = 0 To .Rows.Length - 1
For y = 0 To .Rows(x).Cells.Length - 1
Sheets(1).Cells(x + 1, y + 1).Value = .Rows(x).Cells(y).innertext
Next y
Next x
End With
End Sub
However it doesn't do anything. I changed the url and the table id from the original, but it doesn't work. Any thoughts or help would be appreciated! Thanks!