Get data from web page and paste to excel

flaviu123

New Member
Joined
Aug 20, 2014
Messages
44
Hello! Please help me with VBA code to copy the web page in Excel, using the source code. Thanks in advance!




Sub ExtractWeb()


'to refer to the running copy of Internet Explorer
Dim ie As InternetExplorer
'open Internet Explorer in memory, and go to website
Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate "http://www.bet365.com/extra/ro/results-and-archive/results/?Fromdate=2%2f6%2f2015+12%3a38&SearchPath=fixture&FixtureId=0&Period=1&ChallengeId=0&Teamid=&CompetitionId=20120651&SportId=146&SportDesc=Fotbal%2bvirtual&Todate=3%2f6%2f2015+12%3a38&LanguageId=23&Zoneid=22"


'Wait until IE is done loading page
Do While ie.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop


'show text of HTML document returned
Set html = ie.Document
ie.Document.PutInClipboard


Worksheets("Sheet4").Range("A1").Select
'Range("A1").Value = html.DocumentElement.outerHTML
ActiveSheet.PasteSpecial Format:="Unicode Text", Link:=False, _
DisplayAsIcon:=False
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Leith Ross

Well-known Member
Joined
Mar 17, 2008
Messages
1,874
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
Hello flaviu1223,

Here is a faster way to return the page source. A problem I saw with your code is cell "A1" will not display all of the text from the web page. This macro breaks the code up into lines and pastes a line per row. This makes the format much easier to read.
Code:
<code>Sub ExtractWeb()
    
    Dim PageSrc As String
    Dim Text    As Variant
    Dim Url     As String
    
        Url = "http://www.bet365.com/extra/ro/results-and-archive/results/?Fromdate=2%2f6%2f2015+12%3a38&SearchPath=fixture&FixtureId=0&Period=1&ChallengeId=0&Teamid=&CompetitionId=20120651&SportId=146&SportDesc=Fotbal%2bvirtual&Todate=3%2f6%2f2015+12%3a38&LanguageId=23&Zoneid=22"
        
        With CreateObject("MSXML2.XMLHTTP")
            .Open "GET", Url, False
            .Send
            
            While .readyState <> 4: DoEvents: Wend
            
            If .Status <> 200 Then
                MsgBox "Server Error:  " & .Status & " - " & .StatusText
                Exit Sub
            End If
            
            PageSrc = StrConv(.ResponseBody, vbUnicode)
        End With
        
        Text = Split(PageSrc, vbLf)
        Worksheets("Sheet4").Range("A1").Resize(UBound(Text), 1).Value = Application.Transpose(Text)
                
End Sub
</code>
 
Upvote 0

flaviu123

New Member
Joined
Aug 20, 2014
Messages
44
Thank you for your help. I have not explained well. I want to copy the page that contains hyperlinks (Unicode text format), not source code. What has changed in VBA code?
 
Upvote 0

Leith Ross

Well-known Member
Joined
Mar 17, 2008
Messages
1,874
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
Hello flaviu1223,

Is the result you want the same as choosing "Select All" and "Copy" from the Internet Explorer Edit menu and pasting to the worksheet?
 
Upvote 0

flaviu123

New Member
Joined
Aug 20, 2014
Messages
44
No, VBA code copy and paste in workseet as text format, not Unicode text format. I think the bottom line code is the problem, but I do not know how to fix.
 
Upvote 0

Forum statistics

Threads
1,195,635
Messages
6,010,839
Members
441,569
Latest member
PeggyLee

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
Top