1

I am trying to use XMLHTTP object in VBA to retrive HTML document and insert it to a HTMLDocument object for manipulating elements. But my codes got automation errors. I thoughly checked the codes but couldn't find any possible causes. Can someone help me fix the problem?

Many thanks in avance!

VBA Codes:

Sub RetrieveData()

Dim strURL As String
Dim strResponse As String
Dim objResponse As Object
Dim objHttpReq As Object
Dim objHTML As New HTMLDocument

strURL = "http://www.customs.go.jp/toukei/srch/indexe.htm?M=57&   P=1,1,,,,,,,,,,2013,,9,,,,,,,,,,,,,1,,,,,,,,,,,,,,,,,,,,,,"

Set objHttpReq = CreateObject("MSXML2.XMLHTTP.3.0")
objHttpReq.Open "GET", strURL, False
objHttpReq.send

strResponse = objHttpReq.responseText

objHTML.body.innerHTML = strResponse

MsgBox objHTML.body.innerHTML

End Sub

1 Answer 1

1

Rather than attempting to set the body (which should really work) as you have a full html document you can;

Dim objHTMLAs Object
Set objHTML= CreateObject("htmlfile") 

objHTML.open
objHTML.write objHttpReq.responseText
objHTML.Close
Sign up to request clarification or add additional context in comments.

1 Comment

Really appreciate your reply. I am now able to fetch the document in HTML but there's another issue about the Iframe. Actually I need to get the details about the Frame document and I used contentDocument property of Iframe object. But the result turn out to be "Unspecified Error." for contentDocument. I would like to ask how I can extract the Iframe document in that link?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.