VBA to complete a Internet form

前端 未结 1 1144
無奈伤痛
無奈伤痛 2021-01-28 05:23

I\'m looking for a code to put values from an Excel to a Webpage.

Sub FillInternetForm()
  Dim IE As Object
  Set IE = CreateObject(\"InternetExplorer.Applicatio         


        
相关标签:
1条回答
  • 2021-01-28 05:42

    Ana, Here is a working example. You can easily customized this little bit of code to work for you. One time you must be aware of is that I added a reference to my project under TOOLS -> Preferences -> Microsoft Internet Controls. Also another word of caution is on this line Set Elements on this line, if you are looking for something that does not exists you will end up with an error. This working example I put together goes to stack overflow and finds the elements below footer-menu. Let me know if something does not make sense.

    Sub TryInternetExplorer()
     'Reference to system32\shdocvw.dll  'Microsoft Internet Controls
    Dim IEApp As InternetExplorer
    Set IEApp = New InternetExplorer
    IEApp.Visible = True
    IEApp.Navigate "https://iam.pearson.com/auth/XUI/#login/"
    While IEApp.ReadyState <> READYSTATE_COMPLETE And IEApp.ReadyState <> READYSTATE_LOADED
        DoEvents
    Wend
    
    'wait for the form to load
    Do
    Set form = IEApp.Document.getElementsByTagName("FORM")(0) '1st table
    DoEvents
    Loop While form Is Nothing
    
     IEApp.Document.getElementsByName("callback_0")(0).Value = "Miguel"
     IEApp.Document.getElementsByName("callback_1")(0).Value = "pass"
     IEApp.Document.getElementsByName("callback_2")(0).Click
    
    
    Set Document = Nothing
    Set IEApp = Nothing
    
    
     End Sub
    
    0 讨论(0)
提交回复
热议问题