Cant figure out why I cannot click the button in IE using VBA....

Storm8585

New Member
Joined
Sep 5, 2014
Messages
47
Hi, I am looking to click a button on this webpage Geology of Britain viewer | British Geological Survey (BGS), specifically the one labelled Go To Location (RHS). I cant figure out what its reference is when I look at the source code. My VBA is below, which doesn't work...
Code:
Sub Geol()
    Dim sht As Worksheet
    Dim IE As Object
    Dim ieDoc As HTMLDocument
    Dim Item As Variant
    Dim SignInButton As HTMLInputButtonElement
    Set sht = ActiveSheet
    Set IE = CreateObject("InternetExplorer.Application")
    'Open IE
    IE.Visible = True
    IE.Navigate "[URL="http://mapapps.bgs.ac.uk/geologyofbritain/home.html"]Geology of Britain viewer | British Geological Survey (BGS)[/URL]"
    
    'Wait until site is loaded
    Do While IE.readyState <> 4 'READYSTATE_COMPLETE
        DoEvents
    Loop
    
    'Get the body
    Set ieDoc = IE.Document
    'Fill the information
    'ieDoc.getElementById("txtPostCode").Value = sht.Range("L11").Value
   
      Set SignInButton = ieDoc.getElementById("locationDlg_underlay")
   'SignInButton.Focus
   'SignInButton.Click
End Sub
I have also tried ieDoc.Document.forms(0).submit
but that didt work either. Any suggestions?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Code:
    Dim loc As HTMLSpanElement
    Do
        Set loc = ieDoc.getElementById("dijit_form_Button_1_label")
        DoEvents
    Loop While loc Is Nothing
    loc.Focus
    loc.Click
 
Upvote 0
John, Thanks for the prompt response. However this addition does not work. My code is now
Code:
Sub Geol()
    
    Dim IE As Object
    Dim ieDoc As HTMLDocument
    Dim loc As HTMLSpanElement
    Set IE = CreateObject("InternetExplorer.Application")
    'Open IE
    IE.Visible = True
    IE.Navigate "[url=http://mapapps.bgs.ac.uk/geologyofbritain/home.html]Geology of Britain viewer | British Geological Survey (BGS)[/url]"
    
    'Wait until site is loaded
    Do While IE.readyState <> 4 'READYSTATE_COMPLETE
        DoEvents
    Loop
    
  
    Do
        Set loc = ieDoc.getElementById("dijit_form_Button_1_label")
        DoEvents
    Loop While loc Is Nothing
    loc.Focus
    loc.Click
   
End Sub
It errors on this line Set loc = ieDoc.getElementById("dijit_form_Button_1_label") - runtime error 91. Object variable or With block variable not set. Any thoughts? What am I missing?
 
Upvote 0
Try this:

Code:
Sub Geol()
    Dim sht As Worksheet
    Dim IE As Object
    Dim ieDoc As HTMLDocument
    Dim Item As Variant
    Dim SignInButton As HTMLInputButtonElement
    Set sht = ActiveSheet
    Set IE = CreateObject("InternetExplorer.Application")
    'Open IE
    IE.Visible = True
    IE.Navigate "http://mapapps.bgs.ac.uk/geologyofbritain/home.html"
    
    'Wait until site is loaded
    Do While IE.ReadyState <> 4 'READYSTATE_COMPLETE
        DoEvents
    Loop
    
    'Get the body
    Set ieDoc = IE.Document
    'Fill the information
    'ieDoc.getElementById("txtPostCode").Value = sht.Range("L11").Value
   
      Set SignInButton = ieDoc.getElementById("dijit_form_Button_1")
   SignInButton.Focus
   'SignInButton.Click
End Sub
 
Upvote 0

Forum statistics

Threads
1,222,143
Messages
6,164,175
Members
451,880
Latest member
2da

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