Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input text into html input box using vba

Tags:

html

vba

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!

like image 302
user3107346 Avatar asked Dec 16 '13 13:12

user3107346


People also ask

How do you input text in VBA?

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.

How do you make an input box with multiple inputs in Excel using VBA?

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.


1 Answers

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.

like image 51
Pradeep Kumar Avatar answered Sep 29 '22 03:09

Pradeep Kumar