VBA code to Enter Data to Webpage or IE

enter data to webpage
Spis treści

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

Co czy to:

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

Dlaczego czy to:

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.

Jak 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.

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

Enter Data To Webpage

Krok 2: Copy and Paste the below code in it.

Private Sub wpieautologin()

Ciemny ie Jak SHDocVw.InternetExplorer

Set ie = Nowy SHDocVw.InternetExplorer

ie.Visible = PRAWDA 

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

    Dla Each hyper_link W AllInputs

        Jeśli hyper_link.Name = “wp-submit” Następnie ‘you can use .name, .id etc

            hyper_link.Click

            Exit Dla

        End Jeśli

    Następny

Do

DoEvents

Loop Until ie.readystate = 3

Do

DoEvents

Loop Until ie.readystate = 4

End Pod

Krok 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 Antoni
Anson jest współautorem i założycielem w www.askeygeek.com. Uczenie się czegokolwiek nowego zawsze było jego pasją, ASKEYGEEK.com jest wynikiem jego pasji do technologii i biznesu. Posiada dziesięcioletnie wszechstronne doświadczenie w outsourcingu procesów biznesowych, finansach i księgowości, technologiach informatycznych, doskonałości operacyjnej i inteligencji biznesowej. W trakcie swojej kadencji pracował dla takich organizacji jak Genpact, Hewlett Packard, M*Modal i Capgemini, zajmując różne role i obowiązki. Poza biznesem i technologią jest miłośnikiem kina, który spędza razem godziny, oglądając i ucząc się kina, a także Twórcy Filmowego!

7 Responses

  1. 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

    Imię

    Family Name

    Search

    Dzięki

Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany. Wymagane pola są oznaczone *

Gratulacje!
Zrobiłeś to,
Nie zamykaj!

Dostęp do UberCreate Creator Pro
za darmo!!!

To wyskakujące okienko nie pokaże zależy od Ciebie Ponownie!!!

4
Share to...