I am trying to input a value into a from on an internet explorer page using VBA. I have seen similar posts but can't seem to pinpoint my problem. I am somewhat fluent with VBA but HTML is new to me. The ID attributes change on the webpage I am accessing every time you load the page. Here is a shot of the HTML element I am trying to access:
<input type="text" size="20" style="text-align: right; width: 261px;" autocomplete="off" id="ext-comp-1067" name="user_numbers.1.number_1" class="x-form-text x-form-field x-form- num-field" title="">
The code I am currently using is here:
Sub OpenWebPage()
Dim ObjCollection As Object
Dim i As Long
Dim objElement As Object
Dim doc As Object
Dim form As Object
Dim ie As Object
Set ie = CreateObject("INTERNETEXPLORER.APPLICATION")
ie.Navigate "http://11.182.123.21/#!/view/dashboards/dashboard-1"
ie.Visible = True
While ie.Busy
DoEvents
Wend
Application.Wait Now + TimeValue("00:00:10")
Set ObjCollection = ie.Document.getElementsByName("user_numbers.1.number_1").Value = "123"
End sub
The name "user_number.1.number_1" I think is the only element in the html that I can use to find this input box, the ID changes every time you open the webpage. How do I got about entering a value in this field?
Thank you!
Type “InputBox” and enter a space and you will get a tool for the arguments you need to define. Specify the “Prompt”, message that you want to show to the user. Define a title for the input box, otherwise, it will show the default title. Mention the text that you want to have in the input bar by default.
Creates an input box containing multiple lines (Create Excel VBA InputBox” & vbNewLine & “with multiple lines) with the InputBox function. Assigns the value returned by the InputBox function to a variable (myInputBoxMultipleLinesVariable = inputBox(…)). Displays a message box with the value held by the variable.
As sid mentioned, you have an extra "=" sign.
Replace
Set ObjCollection = ie.Document.getElementsByName("user_numbers.1.number_1").Value = "123"
with
ie.Document.getElementsByName("user_numbers.1.number_1")(0).Value = "123"
This is just off my head and not tested code. If this doesn't work replace (0)
in the above code with (1)
.
If there is no other element on the page with the same name then this will work.
Otherwise replace (0)
in the above statement with appropriate ordinal position.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With