Excel VBA InStr功能 [英] Excel VBA InStr function

查看:179
本文介绍了Excel VBA InStr功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我的InStr函数清楚地是HTML字符串的一部分时返回0?

Why does my InStr function return 0 when it clearly is part of the HTML string?

我不能在没有更多文本的情况下发布。我不能发布这个没有更多的文本。我不能发布没有更多的文字。我不能发布这个没有更多的文字。我不能发布没有更多的文本。

I cannot post this without more text.I cannot post this without more text.I cannot post this without more text.I cannot post this without more text.I cannot post this without more text.I cannot post this without more text.

Sub ImportBPlans()
    Dim BPlan As String, FullHTML As String, URL1 As String, Cut1 As String, T1 As String
    Dim FO As String, LO As String, Other1 As Long

    For i = 2 To LastRow

        T1 = WB1.Cells(i, 1).Value

        URL1 = "http://finance.yahoo.com/q/pr?s=" + T1 + "+Profile"
        FullHTML = GetHTML(URL1)
        BPlan = "&nbsp;</th></tr></table><p>"
        x = Len(FullHTML)
        FO = InStr(FullHTML, BPlan, CompareMethod.Text) + Len(BPlan)
        LO = InStr(FO, FullHTML, "<")
        Cut1 = Left(FullHTML, LO)
        Cut1 = Right(Cut1, FO - LO)
        WB5.Cells(i, 1).Value = Cut1

    Next i


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


推荐答案

尝试这样:

    FO = InStr(1, FullHTML, BPlan, vbTextCompare) + Len(BPlan)

这篇关于Excel VBA InStr功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆