我正在为一个项目上课,我正在尝试从网站www.thehuddle.com导入一个幻想足球查询表。我试图在VBA中编写代码,而不是使用excel工具以获得更高的难度和使用刷新方法的能力。
当我运行代码并使用调试器时,我得到“运行时错误'5'”。任何人似乎都能明白为什么?我找不到无效的程序,或者我没有足够的知识来发现它。
Dim shtQBs As Worksheet, shtRBs As Worksheet, shtWRs As Worksheet, shtTEs As Worksheet
Dim shtDs As Worksheet, shtSTs As Worksheet, shtKs As Worksheet
Set shtQBs = Application.Workbooks("auco6215_project.xlsm").Worksheets("QBs")
Set shtRBs = Application.Workbooks("auco6215_project.xlsm").Worksheets("RBs")
Set shtWRs = Application.Workbooks("auco6215_project.xlsm").Worksheets("WRs")
Set shtTEs = Application.Workbooks("auco6215_project.xlsm").Worksheets("TEs")
Set shtDs = Application.Workbooks("auco6215_project.xlsm").Worksheets("Ds")
Set shtSTs = Application.Workbooks("auco6215_project.xlsm").Worksheets("STs")
Set shtKs = Application.Workbooks("auco6215_project.xlsm").Worksheets("Ks")
shtQBs.Activate
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.thehuddle.com/stats/2014/plays_std.php?ccs=6&pos=qb", _
Destination:=Range("$A$1"))
.CommandType = 0
.Name = "plays_std.php?ccs=6&pos=qb"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = True
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.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
干杯
答案 0 :(得分:0)
我明白了。我注释掉了“.commandtype = 0”这一行,但现在我的第二张表中出现了“运行时错误:sub-scropt超出范围”。谁能明白为什么?
With Sheets("QBs").QueryTables.Add(Connection:= _
"URL;http://www.thehuddle.com/stats/2014/plays_std.php?ccs=6&pos=qb", _
Destination:=Range("A1"))
'.CommandType = 0
.Name = "plays_std.php?ccs=6&pos=qb"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.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
With Sheets("RBs").QueryTables.Add(Connection:= _
"URL;http://www.thehuddle.com/stats/2014/plays_std.php?ccs=6&pos=rb", _
Destination:=Range("A1"))
.CommandType = 0
.Name = "plays_std.php?ccs=6&pos=rb"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.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