私は、API呼び出しを介して解析する必要がある100,000個のURLのリストを持っています。私はそれらを600個以上の連結された文字列のリストに分類しました。各文字列には200個のURLが含まれています。Excel VBA:ループWebクエリ
私は、プロセスをループするために以下のコードを書いて、一度に1つずつ、C列の最後の行にURLに関する返された情報を配置します。しかし、私のループが壊れているように見えて、なぜ(それを見て長すぎるか)わからないが、それはルーキーミスだと思われる。最初の2つの連結された文字列(400個のURL)を実行した後、最初の文字列だけを処理して、行200の情報を書き換えます。
コードは以下のとおりです。私はそれが私の雇用者によって構築された適否システムだと、公共用ではありませんので、解析しようよURLを共有する。
Sub APIDataProcess()
Dim lURLsLastRow As Long
Dim lDataSetLastRow As Long
Dim rngURLDataSet As Range
Dim sURLArray As String
Dim lURLArrayCount As Long
Dim rngArrayCell As Range
lURLsLastRow = Cells(Rows.Count, 1).End(xlUp).Row
lDataSetLastRow = Cells(Rows.Count, 3).End(xlUp).Row
Set rngURLDataSet = Range("A1:A" & lDataSetLastRow)
lURLArrayCount = Range("B1").Value ' placeholder for count increments
sURLArray = Range("A" & lsURLArrayCount).Value
For Each rngArrayCell In rngURLDataSet
If lsURLArrayCount <= lURLsLastRow Then
With ActiveSheet.QueryTables.Add(Connection:="URL;http://test.test.org/test.php", Destination:=Range("C" & lDataSetLastRow))
.PostText = "urls=" & sURLArray
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlOverwriteCells
.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
lURLArrayCount = lURLArrayCount + 1
Range("B1").Value = lURLArrayCount
Application.Wait Now + TimeValue("00:01:00")
Else
Exit Sub
End If
Next rngArrayCell
End Sub