Import content from a site

thbarone

New Member
Joined
Jun 29, 2015
Messages
4
Hi, guys

I found some threads about this, but I'm not having success to make this work.

I have a URL and I need to get the text and a specific hyperlink that it is on the end of the post, on the phrase "Veja a matéria" (sorry, it is in portuguese). Then I'd like to paste it on separate cells on the sheet.

I wrote the code below, but it is not working. First time it would catch the link on the cell, copy the content and paste on the cells at the right side, but it didn't work. Now i'm trying to insert the link where the macro should navigate on a inputbox, but it's still not working.

Can anyone help me with this?

Thanks!

Thats the code

Sub teste()


Dim erow As Long
Dim ele As Object

RowCount = 2

erow = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

Set objIE = CreateObject("InternetExplorer.application")

myurl = InputBox("Insira a URL")

With objIE
.Visible = True
.navigate "myurl.Value"

Do While .busy Or _
.readystate <> 1
DoEvents
Loop

For Each ele In .document.all

Select Case ele.classname
Case "toplink"
RowCount = RowCount + 1
End Select


Next ele


End With

Set objIE = Nothing


End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
thbarone

can you please use code tags around your code (see my example in red below) or use MrExcelHTML as I have done? that way the code is better legible.



Try this, but read through the comments first

<font face=Calibri><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN><br><SPAN style="color:#007F00">' Make sure you dim ALL your variables, _<br>  put Option Explicit at the top of your module</SPAN><br><br><SPAN style="color:#00007F">Sub</SPAN> teste()<br>    <SPAN style="color:#00007F">Dim</SPAN> lLastRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, lRowCount <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> objEle <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN>, objIE <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> sMyURL <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>    <br>    lRowCount = 2<br>    <br>    lLastRow = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row<br>    <br>    <SPAN style="color:#00007F">Set</SPAN> objIE = CreateObject("InternetExplorer.application")<br>    <br>    sMyURL = InputBox("<SPAN style="color:#00007F">In</SPAN>sira a URL")<br>    <br>    <SPAN style="color:#00007F">With</SPAN> objIE<br>        .Visible = <SPAN style="color:#00007F">True</SPAN><br>        .navigate sMyURL    <SPAN style="color:#007F00">' You had this wrong</SPAN><br>        <br>        <SPAN style="color:#00007F">Do</SPAN> <SPAN style="color:#00007F">While</SPAN> .readystate <> 1 <SPAN style="color:#007F00">' you had .busy here which is not a mmember</SPAN><br>            DoEvents<br>        <SPAN style="color:#00007F">Loop</SPAN><br>        <br>        <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> objEle In .document.all<br><br>            <SPAN style="color:#00007F">Select</SPAN> <SPAN style="color:#00007F">Case</SPAN> objEle.classname<br>                <SPAN style="color:#00007F">Case</SPAN> "toplink"<br>                    <SPAN style="color:#007F00">'<<<<>>>> something is missing here, I think. _<br>                     I am assuming that you want to put some text _<br>                     from the page into a cell on your sheet.</SPAN><br>                    lRowCount = lRowCount + 1<br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Select</SPAN><br>        <SPAN style="color:#00007F">Next</SPAN> objEle<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <br>    <SPAN style="color:#00007F">Set</SPAN> objIE = <SPAN style="color:#00007F">Nothing</SPAN><br>    <SPAN style="color:#00007F">Set</SPAN> objEle = <SPAN style="color:#00007F">Nothing</SPAN><br>    <br>    <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br></FONT>
 
Upvote 0

Forum statistics

Threads
1,216,095
Messages
6,128,794
Members
449,468
Latest member
AGreen17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top