2

I have a web form that I want to fill out automatically using VBA. The code below works fine with all text elements in the form but unable to set a value in the combobox of the form (Error 438 is being returned). By inspecting HTML code, I can see that the object does not have any values.

Object details from HTML

<span title="Choose Currency" class="select2-selection__rendered" id="select2-currency-container">Choose Currency</span>
Option Explicit

Sub WebFormDataEntry()

    Dim IE As Object
    Dim doc As HTMLDocument
    
    Set IE = CreateObject("InternetExplorer.Application")
  
    IE.Visible = True
    IE.navigate "https://webaddress"
    
    
    Do While IE.Busy
        Application.Wait DateAdd("s", 1, Now)
    Loop

    
    'Set intellisense.
    Set doc = IE.document
    
    
    With doc
        
        .getElementById("amount").Value = 9.99
        
        .getElementById("iban").Value = "GB7911111111111"
        
        .getElementById("beneficiaryName").Value = "John Smith"
        
        .getElementById("beneficiaryCity").Value = "London"
        
        .getElementById("beneficiaryAddress").Value = "16 Baker's street"
        
        .getElementById("paymentDetails").Value = "inv 4444"
        
        .getElementById("swift").Value = "BRCLGBLO"
        
        .getElementById("beneficiaryBank").Value = "Barcly's bank"
        
        .getElementById("beneficiaryBankAddress").Value = "101 Big Ben street"
        
        
        'UP TO THIS POINT ALL WORKS FINE!
        
        
        'This one returns Error 438. In HTML code this object does not have any values.
        .getElementById("select2-currency-container").Value = "EUR"
        
        
    End With
    
End Sub
QHarr
  • 83,427
  • 12
  • 54
  • 101
Alex
  • 63
  • 1
  • 4
  • Without seeing the HTML of the page, it's hard to say, but the id seems to indicate this might be a jQuery Select2 control. Give this a shot `ie.document.parentWindow.execScript "$('#select2-currency-container').Val('EUR').trigger('change')"`. You may be able to invoke the jQuery methods associated with that control. – Ryan Wildry Oct 21 '20 at 17:03
  • Unfortunately, it did not work. Appreciate your efforts to help. Thank you anyways! – Alex Oct 23 '20 at 14:59
  • You’ll need to provide some more information on this question to get some helpful answers. The relevant HTML, or if possible, the URL to the page would be a good start. Also, what didn’t work with the code shared? Did it result in a different error? Did nothing happen on the page, but the code executed ok? – Ryan Wildry Oct 23 '20 at 23:10
  • I posted a wrong portion of HTML code. See the correct one below. I replaced previous code with .getElementById("currency").Value = "1". Now it works fine. However, visually the selection does not appear. That is, after setting a value to "1" (which is EUR), the drop-box still shows "Choose Currency" instead of EUR. Any suggestions? – Alex Oct 26 '20 at 09:55

0 Answers0