VBA internetexplorer automation

Philip00

New Member
Joined
Aug 16, 2017
Messages
37
Hi All,

I'm trying to do some automation on internet explorer.

I want to hit the search bar "amarindaz" and see the result on A1

I have done the code according this video https://www.google.hu/url?sa=t&rct=...=UU4hVjOnGFA&usg=AOvVaw1BBmESkGfuuZglH1u8wynL

using this code

Sub iepart2()


Dim ie As Object






Set ie = CreateObject("internetexplorer.application")


With ie
.Visible = True
.navigate "https://www.google.co.uk"
Do While .busy
DoEvents
Loop


Do While .readystate <> 4
DoEvents
Loop






Set searchtxt = .document.getelementbyid("q")


searchtxt.Value = "Amarindaz"


.document.forms(0).submit


Do While .busy
DoEvents
Loop


Do While .readystate <> 4
DoEvents
Loop


Set searchres = .document.getelementbyud("resultStats")


ThisWorkbook.Sheets(1).Range("a1") = searchres.innertext



End With



End Sub

However on "Set searchtxt = .document.getelementbyid("q")" part i get error as:

Compile error:

Variable not defined

for what should i define this variable in order to make this code work?

Thank you so much for your help in Advance
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Actually, the id is "lst-ib", not "q". Therefore, try the following instead...

Code:
Set searchtxt = .document.getelementbyid("lst-ib")

Also, you have a typo. It should be...

Code:
Set searchres = .document.[COLOR=#ff0000]getelementbyid[/COLOR]("resultStats")

Hope this helps!
 
Upvote 0
Thank you actually the first one has worked too.

Can somebody help me how to make automation in order to click a button in a page?

here is the source file of the button whiich i want to push it:

Code:
a class="buttonLookUp btn btn-small btn-primary" id="lookup_POD_0_DK_48747_184812_45475" href="javascript:;">strong>Look Up

I have tried this but it won't work

Code:
Set btnObject = ie.document.getElementbyID("lookup_POD_0_DK_48747_184812_45475")    

btnObject.FireEvent ("href")

Thank you in Advance
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top