Home » excel » excel vba – Extract Data from a Web Page – using VBA

excel vba – Extract Data from a Web Page – using VBA

Posted by: admin May 14, 2020 Leave a comment


Using VBA, I need to extract data from webpage http://emops.tse.com.tw/t21/sii/t21sc03_2011_9_e.htm

I am able to fetch all the data using following code:

With ActiveSheet.QueryTables.Add(Connection:="URL;http://emops.tse.com.tw/t21/sii/t21sc03_2012_2_e.htm", Destination:=Range("$A$1"))
        .Name = "67083361_zpid"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlEntirePage
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
End With

But the problem is I don’t want data from whole page. I want data from the table where Industry name is Electron (It is the last table in this case)

Any trick for the same please?

How to&Answers:


.WebSelectionType = xlEntirePage to .WebSelectionType = xlSpecifiedTables


.WebTables = "2" below .WebFormatting = xlWebFormattingNone

‘You will have to use trial and error with the “2” to find the exact table you are wanting to grab