使用 Excel 2007 和 VBA 6.5
我正在尝试自动化数据收集任务,但是我一直遇到“运行时错误 91 -”对象变量或未设置块变量。”这是一个参考问题还是与我的脚本有关。
谢谢。
脚本包含在下面(密码和变量保护)
Sub Basic_Web_Query()
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = True
.Navigate "https://www.urbics.com/Login.php"
Do Until .ReadyState = 4
DoEvents
Loop
.document.all.Item("User Name").Value = "UserName"
.document.all.Item("Password").Value = "Password"
.document.forms(0).submit
End With
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.urbics.com/Urbics.php?hs=a97cd706q9948q11e1qbbacq00259002436c&pgreq=AVTotals&aid=4517", Destination:=Range("$B$4"))
.Name = "q?s=goog_2"
.FieldNames = True
.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 = "1,2"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub