Use VBA to open Chrome and copy text to a cell

kyk8898

New Member
Joined
Sep 2, 2018
Messages
7
Hi there,

I would like to use excel VBA to open the Chrome browser and a specific link and then copy all the text on that page to a cell in a worksheet.

The page I want to copy is as below:
http://bet.hkjc.com/racing/getJSON.aspx?type=win&date=2018-09-02&venue=ST&raceno=1

I found the code below that can open the browser but I don't know how to extract the text and send it to the cell (say A1 in Sheet 3)

==================================================================
Sub test544()

Dim chromePath As String

chromePath = """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"""


Shell (chromePath & "http://bet.hkjc.com/racing/getJSON.aspx?type=qpl&date=2018-09-02&venue=ST&raceno=1")

End Sub
==================================================================

Can anyone help? Thanks
KK
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
.
Try this macro :

Code:
Option Explicit


Sub Test()


    Dim IE As Object
    On Error Resume Next
    Application.DisplayAlerts = False
    
    Sheets("Sheet3").Select
    Range("A1:A1000") = "" ' erase previous data
    Range("A1").Select


    Set IE = CreateObject("InternetExplorer.Application")
        With IE
            .Visible = True
            .Navigate "https://stackoverflow.com/questions/26561527/vba-to-copy-website-data" ' should work for any URL
            Do Until .ReadyState = 4: DoEvents: Loop
        End With


        IE.ExecWB 17, 0 '// SelectAll
        IE.ExecWB 12, 2 '// Copy selection
        ActiveSheet.PasteSpecial Format:="Text", link:=False, DisplayAsIcon:=False
        Range("A1").Select
        IE.Quit


    Application.DisplayAlerts = True
End Sub

Resource : https://stackoverflow.com/questions/26561527/vba-to-copy-website-data

The url link you provided had on one word ....
 
Upvote 0
Hi Logit

The code suddenly does not work today. It seems that it fails to invoke IE and nothing was copied. Please help. Thanks. KK

Sub Test()


Dim IE As Object
On Error Resume Next
Application.DisplayAlerts = False

Sheets("Sheet3").Select
Range("A1:B2") = "" ' erase previous data
Range("A1").Select


Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.Navigate "https://bet.hkjc.com/racing/getJSON.aspx?type=win&date=2018-12-12&venue=HV&raceno=1" ' should work for any URL
Do Until .ReadyState = 4: DoEvents: Loop
End With


IE.ExecWB 17, 0 '// SelectAll
IE.ExecWB 12, 2 '// Copy selection
ActiveSheet.PasteSpecial Format:="Text", link:=False, DisplayAsIcon:=False
Range("A1").Select
IE.Quit


Application.DisplayAlerts = True
End Sub
 
Upvote 0
Oh... one more thing, the macro stopped at the following line:

Do Until .ReadyState = 4: DoEvents: Loop
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

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