Internet Explorer VBA - Problem with Click Button

jkteebs

New Member
Joined
Aug 3, 2016
Messages
5
Hello,

I'm having troubles coming up with a code that will "click" on a specific button on a webpage. The code I have so far is the following:

Code:
Dim IE As InternetExplorerMedium
Dim URL As String
Dim E
Dim btnGo As Object

Sub GetData()
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    URL = 'enter url here
    IE.Navigate URL

    Do
    DoEvents
    Loop Until IE.readyState = 4
                
End Sub
When I click on "Inspect Element" on the button I need, this is the information that appears for it:

<button id="report-prompt-submit__56e88879002270cb4c8b95d2886f00cd_content-reporting-report-data"
type="submit" class="primary report-prompt-submit btn
btn-primary">
Run Report</button>

I just need some help to figure out how to write the code to click on this button. Any help is much appreciated! Thanks!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Welcome to MrExcel forums.

From the HTML you've posted it looks like a simple submit button, therefore you should be able to submit the parent form:
Code:
IE.document.forms(0).submit
assumes the button is in the first form (forms(0)). Use forms(1) if it is the second form, etc.

That's all I can suggest as you haven't provided the URL.
 
Last edited:
Upvote 0
Thanks for the quick response John_w. Unfortunately, the code you provided only works for the search bar. I tried adjusting it to work with different forms (ex: forms(1), forms(2), etc.), but that didn't seem to do the trick. I can't provide the URL because the website only works if I am connected to the company's network. I'm sure that complicates things, but if there are any more suggestions, I'm all ears!
 
Upvote 0
I was able to determine what was causing the problem. Looks like the page wasn't done completely loading, therefore the button wasn't available yet. I had to make Internet Explorer wait a few more seconds to finish loading, and then it was able to find the correct button. Here's the code I ended up using.
Code:
Sub Update ()

Dim IE as Object
Set IE = CreateObject("InternetExplorer.Application")
URL = 'enter website here


        IE.Visible = True
        IE.navigate URL
            Do
            DoEvents
            Loop Until IE.readyState = 4
            Application.Wait (Now + TimeValue("0:00:03"))
            
        IE.document.getElementById("report-prompt-submit__56e88879002270cb4c8b95d2886f00cd_content-reporting-report-data").Click

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,409
Messages
6,124,730
Members
449,185
Latest member
ekrause77

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