Excel VBA: unable to access web controls using MSXML2.XMLHTTP

somashekhar

New Member
Joined
Jun 6, 2013
Messages
5
hi friends,

this is my first post here :).

i am working on a small excel automation to login to a web portal with Baisc Authentication and generate excel report by selecting appropriate values in drop-box .

though i could login with Basic Authentication using MSXML2.XMLHTTP object, i am unable to access the web form controls in the code.





Code:
Set objRequest = New MSXML2.XMLHTTP
With objRequest
  .Open "POST", "http://XXXXXXXXXX?", False, "username", "pwd"
  .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  .send
   htfile = .responseText
   
End With

after this login, i am unable to retrieve the information/status of the web page controls [drop down box] and i am unable to assign the required values to it.

can anybody please help me understand how can i access the web page elements after login using above method!?
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Assign the XMLHTTP ResponseText to a HTMLDocument object inside the With block:
Code:
Dim HTMLdoc As HTMLDocument
Set HTMLdoc = New HTMLDocument
HTMLdoc.body.innerHTML = .responseText
and go from there - without knowing the URL it's difficult to give specific help. NB the above code requires a reference to MS HTML Object Library in Tools - References in the VBA project.
 
Upvote 0
hi John,
thanks for the reply. i have the references set in library. i can also see .responsetext [that's how i could make out the login was successful]. but after assigning .responsetext to variable [htfile is a htmldoc object - my apologies for not updating complete code] i could not access the drop down box on the page [i checked the dropdownbox control name in the html code of the page] to retrieve current status or assign the value.
PS: can't name the actual portal name as it is one of the client site.


Public Sub subx()

Dim strPostData As String
Dim objRequest As Object
Dim htfile As HTMLDocument


Set objRequest = New MSXML2.XMLHTTP
With objRequest
.Open "POST", "http://xxxxxxx.com/reports/", False, "login", "pwd"
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.send
htfile = .responseText

End With



here is the part of source code of the page [i have renamed the controls]. i want to access the drop down control and select the option before generating the report.


________



HTML:
     <td width="20%" align="right">      Axxx    </td><td align="left"><input type="hidden" value="agency_id" name="param_in"></input><select onchange="runRefresh('1')" value="agency_id" name="value_in"><option value="131">Company1    </option><option value="824">Company2    </option><option value="827">Company3    </option><option value="957">Company4    </option></select></td>


PS: i am unable to post the html code as is.. it is resolving into drop down box :(
 
Last edited:
Upvote 0
how can i assign and retrieve value of 'agency_id'?

following code is not working for getting value out from 'agency_id'

idval = htfile.getElementsByID(agency_id)

also i am not aware how to assign the value into it.
 
Upvote 0
You're assigning responseText to htfile incorrectly. Look at my code carefully and compare it with your code.

Sorry, but I can't really help you further without access to the site.
 
Upvote 0
hi John,
i have corrected my code after your first post. i was looking for ways to retrieve/assign value to dropdownbox options.

and yeah i can understand it would be difficult to assist without access. sorry there! and thanks for the help !
 
Upvote 0

Forum statistics

Threads
1,222,115
Messages
6,164,017
Members
451,867
Latest member
csktwyr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top