0

I have a task to add data to the French governments website for export truck movements to the UK. The site is https://www.douane.gouv.fr/enveloppe/en/enveloppe/creer I have all the data in an Excel Spreadsheet but I think the website used KeyDown and Keypress events to accept the information. When I add the data into the site the response is "Field cannot be empty" even though I can see the data is in the form field. This is my VBA test code

Sub postData()

'references Microsoft HTML Object Library and the Microsoft Internet Controls.

    Dim IE As Object
    
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.navigate ("https://www.douane.gouv.fr/enveloppe/en/enveloppe/creer")
    
    'Wait for IE to settle
    Do While IE.Busy
        DoEvents
        Application.Wait DateAdd("s", 1, Now)
    Loop
    
    Set doc = IE.document
    
    For f = 1 To 2
    
        
        Set le_element = doc.getElementsByClassName("form-control input-declaration")
        
        If le_element.Length > 0 Then
            le_element(f - 1).Value = "23NLLIWZQGAK55WD50"
            
            Set evt = doc.createEvent("keyboardevent")
            evt.initEvent "keyDown", True, False
            le_element(f - 1).dispatchEvent evt
        End If
     
        Set Button = doc.getElementsByClassName("bouton-action btn-add-declaration")
                
        If Button.Length > 0 Then
            Button(0).Click
        End If
        
        While IE.Busy
          DoEvents
          Set doc = IE.document
          Application.Wait DateAdd("s", 1, Now)
        Wend
        
        Set doc = IE.document
     
    Next f
    
    'Debug.Print "Ret = " & ret
    
    
    IE.Quit
    Set IE = Nothing

End Sub

I have tried a number of ways to get the data into the field but it appears to need a keypress for each character. I can easily loop through the data a character at a time but cannot figure out how to trigger a keypress event in Excel VBA as I go

  • My advice is to stop using IE but the linked posting is for a little more complex page with evnets to fire. You can look there how it works.https://stackoverflow.com/questions/63294113/automate-ie-via-excel-to-fill-in-a-dropdown-and-continue/63299608#63299608 – Zwenn Jul 25 '23 at 10:42

0 Answers0