Web interaction

Excelor

New Member
Joined
Sep 5, 2014
Messages
18
I have a webpage that I want to be able to update using a vba macro.

So, I was wandering if there was a way to target an <input> element from it's ID and update it, i.e. input a value using details on my excel sheet.

I have scoured the web and cannot find a method, hence me now asking.

Thanks in advance.

Mike
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Further to diddi's reply

Code:
Sub test()


' open IE, navigate to the desired page and loop until fully loaded
    Set IE = CreateObject("InternetExplorer.Application")
    my_url = "https://accounts.google.com/ServiceLogin?hl=en&continue=https://www.google.co.uk/%3Fgfe_rd%3Dcr%26ei%3DyYXxVfSSL8HH8geOxYXQDQ%26gws_rd%3Dssl"
   
    With IE
        .Visible = True
        .navigate my_url
        .Top = 5
        .Left = 5
        .Height = 600
        .Width = 900
  
    Do Until Not IE.Busy And IE.readyState = 4
        DoEvents
    Loop

    End With

' Input the userid
    IE.document.getElementById("Email").Value = "TestName"
    
' Click the "Next" button
    IE.document.getElementById("next").Click

    Do Until Not IE.Busy And IE.readyState = 4
        DoEvents
    Loop
    
    
End Sub

Above is the basic code - to find the elements in HTML press F12(inspect element) which will allow you to look at code for the webpage.

If you are looking to reference say the Userid:
Code:
ID = worksheets("sheet1").cells(1,1).value

and then in sheet 1 cell A1 put your ID
 
Upvote 0
Thanks, both of you.

I have copied your example and, of course, it works. However, I have only changed the address and the ID of the element I am trying to get.

I'm now not getting past the first For Until Loop. It is giving the error "Method 'Busy' of object 'IWebBrowser2' failed".

Have you any idea why this would be happening?

Thanks
 
Upvote 0
Also, Have you got Microsoft Internet controls and Microsoft HTML Object Library selected in References?

Further to that - possibly use IE at a medium integrity level?
 
Upvote 0
It's an old one, 2002!!

Holy mother of.... that's an old one to be using in 2015. I use 2007 and feel like an Grandma! I mostly know about forward compatibility (complete lie, I know nothing about nothing) rather than backward!

May I suggest updating......
 
Upvote 0
May I suggest updating......

You may!! Ha!

However, until then are there any tips.

As I said, your method works it is only when I am changing the target URL that it is breaking. How do I set up IE at medium integrity level? I could give that a go for now?!
 
Upvote 0
Thanks again for your replies. Sorted this now. Found how to set IE at medium integrity level and that works perfectly.

Thanks again guys. Will update my excel when I get around to it!
 
Upvote 0

Forum statistics

Threads
1,214,608
Messages
6,120,500
Members
448,968
Latest member
screechyboy79

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