Open Web page on a userform then detect when I click on a button on that Web page within userform

KeepTrying

Active Member
Joined
Aug 19, 2012
Messages
276
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Dear Experts,

I'd like to run macros on a Web page but as far as I know this is not possible or quite difficult. So I want to at least imitate it. My idea: create a userform, show a Web page on it then detect if e.g. a button was clicked on that Web page on the userform. Then run a macro after clicking (like click event).

I know if I add a "WebBrowser1" control I can easily show a Web page on a userform. Sample code:

Code:
Private Sub UserForm_Initialize()
With Me.WebBrowser1
    .Navigate "https://www.wikipedia.org/"
    .Width = Application.Width
    .Height = Application.Height
    .Top = Application.Top
    .Left = Application.Left
End With
End Sub

But how can I trigger if a button was clicked on that Web page on the userform? I know that controlling Web page is possible from VBA (by creating object called "InternetExplorer.Application") but my question is different.

Web page in the VBA code can be different of course.

Thank you in advance for your help.

Regards,

KeepTrying
 
Last edited:
Glad it has helped.
Code was tested on my computers and it is working as is.
UserForm is a class module itself and isolation of the event part of the code into a separate class module is not required. But it's good to know you have managed it to work.
Have a good weekend! :)
I tried your code on my home PC (Windows 8.1 64 bit and Office 2010 32 bit) and worked great! I really appreciare your time.
Have a great weekend :)
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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