0

I'm trying to use VBA to enter a value into an input box but having no luck! below is my code and the HTML from the website

VBA once the website is open:

IE.GetElementByID("searchForm").Value = "test"

HTML inspecting element:

<form class="well well-search hidden-print" id="searchForm" 
    <div class="row">
        <div class="col-sm-4">
            <input name="search" class="form-control" type="text" size="20" maxlength="20" value="">
        </div>
        <div class="col-sm-2 col-sm-offset-6 right">
            <label>&nbsp;</label>
            <button class="btn btn-success btn-xs showLoadingText form-control" type="submit" data-loading-text="searching...">Search</button>
        </div>
    </div>
</form>
braX
  • 11,506
  • 5
  • 20
  • 33

1 Answers1

0

Your IE variable has the visual representation of being your InternetExplorer application, so I would assume that the code block below is not how you set your IE object (which would be a good thing).

But with that being said, I didn't see where you Set IE, but if you didn't do it as:

Set IE = objIE.Document

then the correct syntax for what you are trying to do would be:

IE.Document.GetElementByID("searchForm").Value = "test"

This is assuming that you have already made sure the webpage has completely loaded before attempting to grab your element. If you hadn't ensured this then you would need to add the following statement before working with your elements:

Do While IE.Busy Or IE.ReadyState < 4
    DoEvents
Loop
K.Dᴀᴠɪs
  • 9,945
  • 11
  • 33
  • 43