我是VBA的新手,并试图整理一个代码,允许我在网站上搜索我的Excel文件中列出的债券信息,并撤回债券的发行日期。我已经能够访问该网站,并使用 F8 手动执行代码,代码似乎工作正常。但是,当我运行宏时,我得到了
错误91:未设置对象变量或With块变量。
我不确定如何解决这个问题,我试图找到更早的答案,因为有很多关于错误91的信息。但似乎没有人能够帮助解决我的具体问题。
请帮助,谢谢。
Dim objIE As InternetExplorer 'special object variable representing the IE browser
Dim datelabel As String
Dim x As String 'for the CUSIP number
Dim y As Integer 'integer variable we'll use as a counter
Dim result As String 'string variable that will hold our result link
'initiating a new instance of Internet Explorer and asigning it to objIE
Set objIE = New InternetExplorer
'make IE browser visible (False would allow IE to run in the background)
objIE.Visible = False
'navigate IE to this web page
objIE.navigate "https://emma.msrb.org/Search/Search.aspx"
'wait here a few seconds while the browser is busy
Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
'DATA SCRAPING Portion
Dim Doc As HTMLDocument
Set Doc = objIE.document
'get issue date
datelabel = Doc.getElementsByClassName("value")(0).innerText 'HERE IS WHERE I HAVE MY PROBLEM
'MsgBox datelabel
End If
Loop
'close the browser
objIE.Quit
这是我想要提取的HTML:
span class =&#34; value&#34; 从: https://emma.msrb.org/SecurityView/SecurityDetails.aspx?cusip=ACDB05F7DCC14B929AC9D2D082A3D9AE0