1

I have a problem regarding excel VBA HTTP request and JavaScript. I want to do a search on an intranet site via "POST" but the submit button does seem to run a JavaScript to reload the site but I don't get how.

Public Function XmlHttpTutorial()

Dim xmlhttp As New MSXML2.XMLHTTP60
Set xmlhttp = CreateObject("MSXML2.serverXMLHTTP")
Dim HTMLDoc As New HTMLDocument

Dim myurl As String

myurl = "http://www.website.de"

xmlhttp.Open "POST", myurl, False
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.setRequestHeader "User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0)1"
xmlhttp.setRequestHeader "Cookie", "serverTimeOffset=-3600149; browserTimeZone=-60;"

xmlhttp.Send ("var1=variable&var2=variable&var3=variable")


Debug.Print xmlhttp.responseText

End Function

This is the button itself

<input type="submit" name="button" tabindex="8" value="Find" onclick="closeWindow();uppercaseForm( this.form );" class="btn-small">

"closeWindow" just closes the window and "uppercaseForm" just puts all Input uppercase

and this is the Header

<form name="arrivalQueryForm" method="post" action="/opslink/arrivalQuery.do" onsubmit="setWindowId(this, 'windowId');">

the setWindowID only gets the window.name and replace brackets.

I have no idea how I get the right site back because nothing seems to work so far.

1 Answer 1

1

The VBA has nothing to do with the HTML as far as I can tell. The XHR is baked in to the HTML form object (note that method=post attribute). That onsubmit is baked in with the HTML form.

I recommend you not use an HTML form element and hand script the XHR in JavaScript so you can see how the mechanism works via a .click event on a button element.

That VBA would be used if you wanted to fetch/XHR from within Excel itself without ever opening a web browser.

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

1 Comment

Thats what I try to fetch the data from withing Excel via XHR but I get a previous page which seems to do with the Javascript part of the website I try to reach.

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.