简体   繁体   English

如何从Excel VBA中的Internet Explorer中提取特定表

[英]How do I pull a certain table from Internet Explorer in Excel VBA

Hello I've scoured the internet trying to find a solution to this problem. 您好,我搜寻了互联网,试图找到解决此问题的方法。

  • I'm trying to pull a certain table from this a private website using . 我正在尝试使用从这个私有网站中提取某个表。
  • I came across this code that allows me to pull all the tables but I only need one table - is there any way I can edit this to pull just one specific table? 我遇到了这段代码,该代码允许我提取所有表,但我只需要一个表-有什么方法可以编辑此代码以仅提取一个特定表?

code

Sub GetAllTables(doc As Object)

' get all the tables from a webpage document, doc, and put them in a new worksheet

Dim IE As Object
Dim ws As Worksheet
Dim rng As Range
Dim tbl As Object
Dim rw As Object
Dim cl As Object
Dim tabno As Long
Dim nextrow As Long
Dim I As Long
Dim oXL As Excel.Application

Set ws = Sheet1

For Each tbl In doc.getElementsByTagName("TABLE")
tabno = tabno + 1
nextrow = nextrow + 1
Set rng = ws.Range("C" & nextrow)
rng.Offset(, -1) = "Table " & tabno
For Each rw In tbl.Rows
For Each cl In rw.Cells
rng.Value = cl.outerText
Set rng = rng.Offset(, 1)
I = I + 1
Next cl
nextrow = nextrow + 1
Set rng = rng.Offset(1, -I)
I = 0
Next rw
Next tbl

ws.Range("C:N").ClearFormats

Sure there is. 当然可以。 Which table do you need to pull? 您需要拉哪张桌子? Either you can identify it by index position: 您可以通过索引位置来标识它:

Dim t as Integer    'represents the index position of the table you want to obtain.
t = 0
Set tbl = doc.getElementsByTagName("TABLE")(t)

Or, if the index position is not known, you would need to develop some other logical tests within a For/Each loop. 或者,如果索引位置未知,则需要在For/Each循环中开发其他逻辑测试。 Note: this is a very simplistic example with pseudo-code. 注意:这是使用伪代码的非常简单的示例。 You may require more complex logic/conditions to determine which table is the correct table in the collection: 您可能需要更复杂的逻辑/条件才能确定哪个表是集合中的正确表:

For each tbl in doc.getElementsByTagName("TABLE")
    If tbl.__some_property__ = "something" Then
        Exit For
    End If
Next

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM