我正在尝试从该网站提取数据:http://securities.stanford.edu/filings.html?page=1
每个“页面”是一个包含 21 个项目的表格。我想从 97 页中提取数据,但我无法将其自动化,以便宏循环遍历所有 97 页,并从单元格 A1 开始每 21 行放置一次结果。 (序列:a1、a22、a43 等...)
这是我得到的,但我不想编辑代码 97 时间来获取所有页面。知道如何使任务自动化吗?
Sub Macro1()
' Macro1 Macro
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://securities.stanford.edu/filings.html?page=1", Destination:=Range( _
"A1"))
.Name = "filings.html?page=1"**
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
end Sub
最佳答案
For x = 1 to 97
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://securities.stanford.edu/filings.html?page=" & x, Destination:=Range( _
"A" & (1 + ((x - 1) * 21)))
.Name = "filings.html?page=" & x
End With
Next
x 包含页码,并且单元格很复杂,使其从 A1 而不是 A21 开始。
你可以做到
0 to 96
和单元格& (1 + (x + 21))
以及名称和查询x + 1
.
关于vba - 在循环中使用 From Web Query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30147248/