我正在尝试使用 excel 网络查询从多个网页中提取数据。
代码在前 10 个循环中运行良好,之后我收到错误消息:
“运行时错误 1004:无法打开 URL。连接到此 Internet 站点的时间超过了分配的时间”
我会很感激任何指针。网站链接在这里
完整代码如下:
Sub DataPull()
Dim page As Integer
Dim Summary As Worksheet
Dim Query As Worksheet
Dim x As Integer
Dim n As Integer
Set Summary = ActiveWorkbook.Sheets("Summary")
Set Query = ActiveWorkbook.Sheets("Query")
x = 2
For n = 1 To 11
With
Query.QueryTables.Add(Connection:="URL;http://www.skmm.gov.my/link_file/registers1/_
aa2.aspcc=83885232640314699294053&vl=&aa=celcom_cell&fpg=" &n,_
Destination:=Query.Cells(1, 1))
.Name = "aa2.asp?cc=83885232640314699294053&vl=&aa=celcom_cell&fpg=1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlOverwriteCells
.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
Query.Range("A6:H35").Copy Destination:=Summary.Range("A" & x)
x = x + 30
Query.QueryTables(1).Delete
Next n
End Sub`