VBA HTML
Jump to navigation
Jump to search
Retrieve HTML
Reference | Library |
---|---|
Microsoft XML | MSXML2 |
Microsoft HTML | MSHTML |
Public Sub retrieveHtml(strUrl As String)
Dim objServerXmlHttp As MSXML2.ServerXMLHTTP
Dim objHtmlDocument As MSHTML.HTMLDocument
'Send request to web site
Set objServerXmlHttp = New MSXML2.ServerXMLHTTP
With objServerXmlHttp
.Open bstrMethod:="POST", bstrUrl:=strUrl, varAsync:=False
.send varBody:=vbNullString
End With
'Store HTML in object
Set objHtmlDocument = New MSHTML.HTMLDocument
With objHtmlDocument
.body.innerHTML = objServerXmlHttp.responseText
End With
End Sub
Save HTML to file
Reference | Library |
---|---|
Microsoft HTML | MSHTML |
Microsoft Scripting Runtime | Scripting |
Public Sub saveHtml(objHtmlDocument as MSHTML.HTMLDocument, strFile As String)
Dim fso As Scripting.FileSystemObject
Dim tst As Scripting.TextStream
Set fso = New Scripting.FileSystemObject
Set tst = fso.CreateTextFile(FileName:=strFile, Overwrite:=True, Unicode:=True)
With tst
.Write objHtmlDocument.body.innerHTML
FollowHyperlink Address:=strFile
End With
End Sub