参数类型不匹配

时间:2015-09-15 23:23:15

标签: excel vba excel-vba

代码的第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 = "&nbsp;</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

2 个答案:

答案 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 = "&nbsp;</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)

您的变量定义部分是个问题。你需要告诉它在逗号之前是什么类型(它不被用作英语)。

如下所示,如果您没有指定类型,则清空

Dim Issue