代码的第5行给出了一个参数类型错误匹配。请帮帮我?
Sub ImportBPlans()
Dim BPlan, FullHTML, URL1, Cut1 As String
Dim FO, LO, Other1 As Integer
URL1 = "http://finance.yahoo.com/q/pr?s=AAPL+Profile"
FullHTML = GetHTML(URL1)
BPlan = " </th></tr></table><p>"
FO = InStr(FullHTML, BPlan) + Len(BPlan)
LO = InStr(FO, FullHTML, "<")
Cut1 = Left(FullHMTML, LO)
Cut1 = Right(Cut1, FO - LO)
WB5.Cells(1, 1).Value = Cut1
End Sub
Function GetHTML(URL As String) As String
Dim HTML As String
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", URL, False
.Send
GetHTML = .ResponseText
End With
End Function
答案 0 :(得分:2)
您将预期的 HTMLDocument 与其字符串内容混淆。
Sub ImportBPlans()
Dim BPlan As String, FullHTML As String, URL1 As String, Cut1 As String
Dim FO As String, LO As String, Other1 As Long
URL1 = "http://finance.yahoo.com/q/pr?s=AAPL+Profile"
FullHTML = GetHTML(URL1)
BPlan = " </th></tr></table><p>"
FO = InStr(FullHTML, BPlan) + Len(BPlan)
LO = InStr(FO, FullHTML, "<")
Cut1 = Left(FullHTML, LO)
Cut1 = Right(Cut1, FO - LO)
Debug.Print Cut1
'WB5.Cells(1, 1).Value = Cut1
End Sub
Function GetHTML(URL As String) As String
Dim HTML As String
Dim htmlBDY As New HTMLDocument
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", URL, False
.Send
htmlBDY.body.innerHTML = .responseText
GetHTML = htmlBDY.body.outerHTML
End With
End Function
在.responseText
中收到的HTML文档比将Ctrl + U点击到查看源时所预期的要多。要将源作为字符串从函数传回,必须将其解析为一个简单的字符串。
答案 1 :(得分:0)