微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法使用VBA在Web表单的组合框中设置值

如何解决无法使用VBA在Web表单的组合框中设置值

我有一个要使用VBA自动填写的Web表单。下面的代码对表单中的所有文本元素均能正常工作,但无法在表单的组合框中设置值(返回错误438)。通过检查HTML代码,我可以看到该对象没有任何值。

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。