jeudi 4 juin 2020

Importing a Table

Hello from a vba newbie,

I'd used below vba codes to copy tables to excel for many times successfully. But i don't know why it doesn't work this time to copy email address from sfc public website (eg. https://www.sfc.hk/publicregWeb/corp/AAA121/addresses?locale=en)

I tried other vba codes suggested online (as below), but still no luck. I tried another logic to browse the website and click button "addresses". However, this logic didn't work too.

http://www.vbforums.com/showthread.php?868739-RESOLVED-VBA-click-button-in-a-webpage https://superuser.com/questions/1325958/pressing-a-button-in-an-ie-page-using-vba

Can anyone save me from this headache, please!

My VBA code:

Sub Macro()


Dim objWeb As QueryTable
Dim sWebTable As String
 'count down the tables on the URL listed in the query
 'Retrieve the 2nd table from the web page.
sWebTable = 1
 'Sets the url to run the query and the destination in the excel file

Dim N As Integer
For N = 1 To 10


'Worksheets("Sheet5").Range("C1:R10").Clear


Set objWeb = ActiveSheet.QueryTables.Add( _
Connection:="URL;https://www.sfc.hk/publicregWeb/corp/" & Range("A" & N) & "/addresses?locale=en", _
Destination:=Range("C1"))

With objWeb

    .WebSelectionType = xlSpecifiedTables
    .WebTables = sWebTable
    .Refresh BackgroundQuery:=False
    .SaveData = True
End With
Set objWeb = Nothing

Range("B" & N).Value = Range("C1").Value

Next N

End Sub



Aucun commentaire:

Enregistrer un commentaire