来自使用 VBA 的受密码保护的网站的数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10506833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Data from password protected website using VBA
提问by Alex Paras
using Excel 2007 and VBA 6.5
使用 Excel 2007 和 VBA 6.5
I'm trying to automate a data collection task, however i keep running into the "Runtime Error 91 - "Object Variable or With Block Variable not Set." Is this a reference issue or does it have to do with my script.
我正在尝试自动执行数据收集任务,但是我一直遇到“运行时错误 91 -”对象变量或块变量未设置。”这是参考问题还是与我的脚本有关。
Thanks.
谢谢。
Script is included below (password and variable protected)
脚本包含在下面(密码和变量保护)
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"))
.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
采纳答案by Siddharth Rout
Change these lines
更改这些行
.document.all.Item("User Name").Value = "UserName"
.document.all.Item("Password").Value = "Password"
to
到
.document.all.Item("loginUserName").Value = "UserName"
.document.all.Item("loginUserPassword").Value = "Password"
And try again.
然后再试一次。