VBA to input value by .GetElementsByname not ID (1 Viewer)

jayinthe813

New member
Local time
Yesterday, 21:04
Joined
Sep 6, 2012
Messages
6
So im stuck trying to figure out how to enter data into a web form field via VBA, without using its ID via DOM (referenced MSHTML and MS internet controls). I have this code below:

Code:
Dim HTMLDoc As MSHTML.HTMLDocument(browser functions)
 Set HTMLDoc = Browser.document With HTMLDoc  .getElementById("USER").setAttribute "value", "employee" .getElementById("PASSWORD").setAttribute "value", "pass" .getElementById("Button").click  End With
Which works perfectly, but the next page I get to, the text field i need to add a variable into only has a Name, and not ID:

Code:
[SIZE=4]<TD align=left ><INPUT class=data name=dataNum size=9 maxlength=9> </TD>[/SIZE]
Code:
.getElementsByName ("dataNum")
I have set the above code which should grab the name, but it will not let me do
.value OR .setattribute, (it appears getelementbyid can) so I dont know how to tell it to insert my variable into the field, then click submit.

I have scoured google, but the only thing I can really find on this concerns javascript, and yet it should be very similar (using DOM), but those cases are still using the ID to get the element. Anyone have any ideas? :banghead:
 

jayinthe813

New member
Local time
Yesterday, 21:04
Joined
Sep 6, 2012
Messages
6
Thanks for the suggestion...

I was able to get it to work using:

HTMLDoc2.forms("FORMNAME").TEXTFIELDNAME.Value
 

Users who are viewing this thread

Top Bottom