Code VBA pour saisir des données sur une page Web ou IE

enter data to webpage
Table des matières

VBA Enter Data into webpage – IE Automation using VBA GetElementByID function

Quoi est-ce :

If you are trying to do ie automation or trying to enter data to webpage using VBA then this post if for you. We will show the step by step instructions on how to enter/fill data in ie using VBA.

Enter Data To WebpagePin

Pourquoi est-ce :

This is very helpful when you want to enter or fill multiple fields in a webpage regularly. Or if you want to login to website in a single click without using the browser’s default Remember My Password option etc.

Comment to enter data to webpage using vba




In this example we are using Excel VBA for IE Automation however you can use any VBA supported platform.

Étape 1: Open the Excel workbook and got to VBA code builder (Alt + F11) and Open a New Module.

Enter Data To Webpage

Étape 2: Copy and Paste the below code in it.

Subdivision privée wpieautologin()

Faible ie Comme SHDocVw.InternetExplorer

Set ie = Nouveau SHDocVw.InternetExplorer

ie.Visible = Vrai 

ie.Navigate “https://www.askeygeek.com/wp-admin” ‘we are trying to login to askeygeek.com admin page

Do

DoEvents

Loop Until ie.readystate = 4

‘ie READYSTATE has 5 different status codes, here we are using status 4:

‘Uninitialized = 0

‘Loading = 1

‘Loaded = 2

‘Interactive =3

‘Complete = 4 

Call ie.Document.GetElementByID(“user_login”).SetAttribute(“value”, “testUser”)

Call ie.Document.GetElementByID(“user_pass”).SetAttribute(“value”, “testPass12345”)

 ‘to find the “<input……/>” tag hyper link and to click the button

Set AllInputs = ie.Document.getelementsbytagname(“input”) ‘you can use any tagname as you wish

    Pour Each hyper_link Dans AllInputs

        Si hyper_link.Name = “wp-submit” Then ‘you can use .name, .id etc

            hyper_link.Click

            Exit Pour

        End Si

    Suivant

Do

DoEvents

Loop Until ie.readystate = 3

Do

DoEvents

Loop Until ie.readystate = 4

End Sous

Étape 3: Click the Run button or F5.(Also you can insert a button/shape in excel sheet then right click and assign this macro to run every time.)

Enter Data To Webpage

Notes 1: Make sure ‘Microsoft Internet Controls’ is enabled from the Tools – References.

Ie AutomationPin

Notes 2: Right click the webpage to and click View source to find the GetElement values

GetelementsbytagPin



Picture of Anson Antony
Anson Antoine
Anson est auteur collaborateur et fondateur de www.askeygeek.com. Apprendre quelque chose de nouveau a toujours été sa passion, ASKEYGEEK.com est le résultat de sa passion pour la technologie et les affaires. Il possède une décennie d'expérience polyvalente dans l'externalisation des processus métiers, la finance et la comptabilité, les technologies de l'information, l'excellence opérationnelle et la business intelligence. Au cours de son mandat, il a travaillé pour des organisations telles que Genpact, Hewlett Packard, M*Modal et Capgemini dans divers rôles et responsabilités. En dehors des affaires et de la technologie, c'est un cinéphile qui passe des heures ensemble à regarder et à apprendre le cinéma et un cinéaste aussi !

7 Responses

  1. hi team, i need to fill the data in Browser tab, which is already opened and navigated to the exact page, where i need to fill my data, please provide the VBA code to deal with this session.

  2. Can you help me here?
    There is no id or value set in the following lines of code, how do I insert say into the “lastnameFilter” or “firstnameFilter”?

    Learner’s ID

    Prénom

    Family Name

    Search

    Remerciements

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Toutes nos félicitations!
Tu l'as fait,
Ne fermez pas !

Accès UberCreate Creator Pro
gratuitement!!!

Cette fenêtre contextuelle ne montrera pas à toi de voir encore!!!

4
Share to...