在VBA Excel中读取HTML文件

Alp*_*n67 2 vba

我想阅读VBA中的HTML代码(类似于Java中的URL).我需要将它保存在一个字符串中.我事后解析它.

alpan67

Dan*_*iel 9

这是给你的功能.它将返回给定URL返回的HTML的String.

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
Run Code Online (Sandbox Code Playgroud)

只需确保您提供的网址格式正确.IE包括http://https://在适当的情况下.

例如:GetHtml("www.google.com")不正确.
你想要的GetHtml("https://www.google.com/")