3

I've been looking around but I can't find any way to do what I'm trying to do here. It may not even be possible, but I'm using the MSXML2 driver to connect to a web page. The response text I get is just the HTMl of the web page. Not exactly what I was looking for, but I might be able to work with it. From there, I wanted to try to set an HTML document object to that response text, since it is just an HTML page, but I get a type mismatch. I'm not sure if this would get me any closer to a solution to my issue, but I figured it would be worth asking here. Here is what I'm doing:

Sub GetResponseText()
    Dim Document as HTMLDocument
    Dim xmlHTTP As MSXML2.ServerXMLHTTP
    Set xmlHTTP = New MSXML2.ServerXMLHTTP
    xmlHTTP.Open "POST", "http://SomeServerName.dev/SomePage.Aspx", False, "User", "Password"
    xmlHTTP.send "Doesn't matter what I put here, response always the same"
    Set Document = xmlHTTP.responseText   <----- No dice.  Type mismatch here.

So, As I was saying, I'm not even sure if this would work at all. Just thought I'd check in. The overview of what I'm trying to do is this is an internal application that I'm trying to fill out for the company I work for. I've had poor luck waiting on AJAX to complete requests trying to automate the HTML directly, so I'm wondering if maybe something like this would help. Any thoughts?

1
  • You cannot assign a 'string' to an 'object'. You should; - create an instance of the document and call the method ".Parse()/.Load()" (whatever the interface is for loading html in string form) on it with your response text. Commented Nov 13, 2013 at 16:05

1 Answer 1

5

You can create html document using CreateObject("htmlfile") and assign the xmlhttp response text.

Sub GetResponseText()

    Dim Document As HTMLDocument
    Dim xmlHTTP As MSXML2.ServerXMLHTTP
    Set xmlHTTP = New MSXML2.ServerXMLHTTP
    xmlHTTP.Open "POST", "http://SomeServerName.dev/SomePage.Aspx", False, "User", "Password"
    xmlHTTP.send "Doesn't matter what I put here, response always the same"

    Dim doc As Object
    Set doc = CreateObject("htmlfile")
    doc.body.innerHTML = xmlHTTP.responseText
    debug.print doc.body.innerHTML


End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks man! I actually ended up using a slightly modified version of this. I set the document I was already using to a new HTML document and then simply set the body.innerHTML property of that equal to the response text. Basically the same thing you outlined. Thanks again.

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.