【发布时间】:2015-12-30 23:27:52
【问题描述】:
经过一些更新,我已经能够提出一个接近工作的代码。我遇到的唯一问题之一是宏没有从最后一页抓取数据。对于昨天的数据,有 6 页数据,但宏只抓取第 5 页。但奇怪的是,如果我用 2 天前的相同代码抓取数据,我可以检索所有数据7 或 8 页。我不确定为什么会这样。有任何想法吗?这是更新后的代码。
'Macro to query Delinquency Status Search for DFB Counties
'Run Monday to pull data from Friday
Sub queryActivityDailyMforFWorking()
Dim nextrow As Integer, i As Long
Dim dates
dates = Date - 1
i = 1
Application.ScreenUpdating = False
Application.DisplayStatusBar = True
Do
'i = i + 1
Application.StatusBar = "Processing Page " & i
nextrow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row + 1
'lastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlToLeft).Column + 1
'With ActiveSheet.QueryTables.Add(Connection:= _
'"URL;https://www.myfloridalicense.com/delinquency_results.asp?SID=&page=" & i + county + x & "&status=NS&send_date=" & dates & "&search_1.x=1", _
'Destination:=Range("A" & nextrow))
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;https://www.myfloridalicense.com/delinquency_results.asp?SID=&page=" & i & "&county_1=11,%2012,%2013,%2014,%2015,%2016,%2017,%2018,%2019,%2020,%2021,%2022,%2023,%2024,%2025,%2026,%2027,%2028,%2080,%2029,%2030,%2031,%2032,%2033,%2034,%2035,%2036,%2037,%2038,%2039,%2040,%2041,%2042,%2043,%2044,%2045,%2046,%2047,%2048,%2049,%2050,%2051,%2052,%2053,%2054,%2055,%2056,%2057,%2058,%2059,%2079,%2060,%2061,%2062,%2063,%2064,%2067,%2068,%2069,%2065,%2066,%2070,%2071,%2072,%2073,%2078,%2074,%2075,%2076,%2077&status=NS&send_date=" & dates & "&search_1.x=1", _
Destination:=Range("A" & nextrow))
'.Name = _
"2015&search_1.x=40&search_1.y=11&date=on&county_1=AL&lic_num_del=&lic_num_rep=&status=NS&biz_name=&owner_name="
.FieldNames = False
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "10"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
'autofit columns
Columns("A:G").Select
Selection.EntireColumn.AutoFit
'check for filter, if not then turn on filter
ActiveSheet.AutoFilterMode = False
If Not ActiveSheet.AutoFilterMode Then
ActiveSheet.Range("A:G").AutoFilter
End If
i = i + 1
End With
ActiveCell.value = ActiveCell.Value * 2
ActiveCell.Offset(1,0).Select
Loop Until IsEmpty(ActiveCell.Value)
Application.StatusBar = False
'Align text left
Cells.Select
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End Sub
【问题讨论】:
-
即使有,它也会不断迭代。我为不同的搜索编写了相同的代码,即使它的页面少于 25 页,它仍然会继续迭代直到达到 25。
-
我明白你的意思,但这似乎对我所做的没有意义。从某种意义上说,我正在运行的另一个 Sub,同样的代码提醒你,只是不同的搜索代码,运行没有问题,我知道 13 不存在,但它仍然运行并迭代。
-
我尝试了不同的日期,代码能够迭代并且没有出现错误
-
查询在到达 .Refresh BackgroundQuery 之前不会真正执行,因此它实际上可以是之前查询中的任何内容。也许尝试一次注释掉一个,直到您不再收到错误为止。
-
使用现在的代码,如果你要执行代码,它会抛出错误。但是,当我将日期更改为从 12/16 开始抓取信息时,它可以毫无问题地进行抓取。我只是不明白为什么我可以从其他日子刮取数据,而不是昨天。我已经尝试在 .refresh backgroundquery 之前注释掉行,但我仍然收到相同的错误。
标签: vba excel excel-2010