Código VBA para inserir dados na página da Web ou IE

enter data to webpage
Índice

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

O que é isso:

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

Por que é isso:

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.

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

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

Enter Data To Webpage

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

Subprivado wpieautologin()

Escurecer ie Como SHDocVw.InternetExplorer

Set ie = New SHDocVw.InternetExplorer

ie.Visible = True 

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

    Para Each hyper_link Em AllInputs

        Se hyper_link.Name = “wp-submit” Então ‘you can use .name, .id etc

            hyper_link.Click

            Exit Para

        End Se

    Próximo

Do

DoEvents

Loop Until ie.readystate = 3

Do

DoEvents

Loop Until ie.readystate = 4

End Sub

Etapa 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 Antônio
Anson é autor colaborador e fundador da www.askeygeek.com. Aprender algo novo sempre foi sua paixão, ASKEYGEEK.com é o resultado de sua paixão por tecnologia e negócios. Ele tem uma década de experiência versátil em terceirização de processos de negócios, finanças e contabilidade, tecnologia da informação, excelência operacional e inteligência de negócios. Durante sua gestão, ele trabalhou para organizações como Genpact, Hewlett Packard, M*Modal e Capgemini em diversas funções e responsabilidades. Fora dos negócios e da tecnologia, ele é um cinéfilo que passa horas juntos assistindo e aprendendo Cinema e também Cineasta!

7 respostas

  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

    Primeiro nome

    Family Name

    Search

    Obrigado

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

Parabéns!
Você conseguiu,
Não feche!

Levante-se para 60.000 Créditos de personagem UberTTS de graça!!!

Este pop-up não vai aparecer você decide de novo!!!

UberTTS
4
Share to...