XL 2010: Macro to open a browser and go to a hardcoded Webpage?

TechTank

Board Regular
Joined
Sep 5, 2011
Messages
92
I'm sure any number of the members here can point out the code I need but my Google search (other search engines are available) has come up empty :eek:

I'm trying to execute a button on a custom ribbon in Excel 2010 that links to a macro (I can do this bit :)). The problem is that I'm not sure of the code to put in the macro to open up a web browser and go to a particular web site or if I could add the URL to the XML in the CustomUI which would be even better.

Any help greatly appreciated.

Mark.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
This code will open Web Browser and go to a website

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> IE_Autiomation()<br>    <SPAN style="color:#00007F">Dim</SPAN> i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> IE <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> objElement <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> objCollection <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN><br>    <SPAN style="color:#007F00">' Create InternetExplorer Object</SPAN><br>    <SPAN style="color:#00007F">Set</SPAN> IE = CreateObject("InternetExplorer.Application")<br>    <SPAN style="color:#007F00">' You can uncoment Next line To see form results</SPAN><br>    IE.Visible = <SPAN style="color:#00007F">True</SPAN><br>    <SPAN style="color:#007F00">' Go to website</SPAN><br>    IE.Navigate "http://www.bbc.com/"<br>    <SPAN style="color:#007F00">' Statusbar</SPAN><br>    Application.StatusBar = "www.bbc.com is loading. Please wait..."<br>    <SPAN style="color:#007F00">' Wait while IE loading...</SPAN><br>    <SPAN style="color:#00007F">Do</SPAN> <SPAN style="color:#00007F">While</SPAN> IE.Busy<br>        Application.Wait DateAdd("s", 1, Now)<br>    <SPAN style="color:#00007F">Loop</SPAN><br><SPAN style="color:#007F00">'    IE.Visible = True</SPAN><br>    <SPAN style="color:#007F00">' Clean up</SPAN><br>    <SPAN style="color:#00007F">Set</SPAN> IE = <SPAN style="color:#00007F">Nothing</SPAN><br>    <SPAN style="color:#00007F">Set</SPAN> objElement = <SPAN style="color:#00007F">Nothing</SPAN><br>    <SPAN style="color:#00007F">Set</SPAN> objCollection = <SPAN style="color:#00007F">Nothing</SPAN><br> <br>    Application.StatusBar = ""<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
That's fantastic! For using it in the Ribbon from the CustomUI14.xml add (control As IRibbonControl) at the end of Sub <macro_name> (control As IRibbonControl).

The code looks like the following for anyone else searching for an answer (change the values in NAME:

Code:
Sub [B][COLOR=Red]MACRO_NAME[/COLOR][/B] <insert macro="" name="">(control As IRibbonControl)
    Dim i As Long
    Dim IE As Object
    Dim objElement As Object
    Dim objCollection As Object
    
    ' Create InternetExplorer Object
    Set IE = CreateObject("InternetExplorer.Application")
    ' You can uncoment Next line To see form results
    IE.visible = True
    ' Go to website
    IE.Navigate "[B][COLOR=Red]WEB URL[/COLOR][/B]<insert web="" url="">"
    ' Statusbar
    Application.StatusBar = "[B][COLOR=Red]THIS PAGE[/COLOR][/B]<insert page="" name=""> is loading. Please wait..."
    ' Wait while IE loading...
'    Do While IE.Busy
'        Application.Wait DateAdd("s", 1, Now)
'    Loop
'    IE.Visible = True
    ' Clean up
    Set IE = Nothing
    Set objElement = Nothing
    Set objCollection = Nothing

    Application.StatusBar = ""
End Sub
For creating custom Ribbons for Office 2010 check out http://www.rondebruin.nl/ribbon.htm.

Regards,

Mark.</insert></insert></insert></macro_name>
 
Last edited:
Upvote 0
This code will open Web Browser and go to a website

Hi Trevor, I'm using one application, in that i want access the tab.

Just like entering into Google, then i have to go to gmail link in that page.

now i can go to google by using the below code, i want to know how to acces 'gmail' link in the google page. Can you please help on this?

Sub IE_Autiomation()
Dim i As Long
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
' Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
' You can uncoment Next line To see form results
IE.Visible = True
' Go to website
IE.Navigate "http://www.google.com/"
' Statusbar
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
' IE.Visible = True
' Clean up
Set IE = Nothing
Set objElement = Nothing
Set objCollection = Nothing

Application.StatusBar = ""
End Sub

wait for your reply.
 
Upvote 0

Forum statistics

Threads
1,216,212
Messages
6,129,531
Members
449,515
Latest member
lukaderanged

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