PDA

View Full Version : Open from the default browser



adamsm
05-20-2011, 04:00 AM
Hi,

How could I make the following code to open the web page from the default web browser instead of internet explorer.

Sub OpenWebPage()
Dim ie As Object, oDoc As Object
Dim ieForm As Variant
Dim WebPage As String

Set ie = CreateObject("InternetExplorer.Application")

WebPage = "http://www.mywebsite.com"

ie.Visible = True

ie.navigate WebPage


Do Until ie.ReadyState = 4 'READYSTATE_COMPLETE
Loop

Set oDoc = ie.Document
Set ieForm = oDoc.forms(0)

ieForm(0).innerText = ActiveWorkbook.ActiveSheet.Range("A2").Text


Do Until ie.ReadyState = 4 'READYSTATE_COMPLETE
Loop
End Sub
Any help on this would be appreciated.

Kenneth Hobs
05-20-2011, 05:39 AM
I see that question asked every so often but then I have to ask, why would you want to do that? The code that you are using is for MSIE specifically. You can not expect it to work for just any browser.

However, to answer your question literally:
ThisWorkbook.FollowHyperlink "http://www.vbaexpress.com/forum/showthread.php?t=37494", NewWindow:=True

adamsm
05-20-2011, 05:44 AM
Thanks for the reply; but does your code mean I have to remove the rest of the code and just leave the line in your code?

Charlize
05-20-2011, 05:53 AM
This one will use firefox. Problem is I have to write a handler for the windows that are open. Then grab the window and try to see if I can reach the inputbox.

Other way would be by parsing the internetpage with some kind of manipulation that i don't use (and would it work with firefox ?)

CreateObject("Wscript.Shell").Run ("firefox")Charlize

ps. for the interested ones, I did test the code (from the OP) and it works on my computer (with ie 8 - excel 2003)

adamsm
05-20-2011, 06:38 AM
Thanks for the reply. I guess as mentioned in the previous replies the code works fine with the internet explorer 8 after the installation.

But since using a webbrowser control is much efficient in this case I've made a slight change to the code so that when the userform loads it takes the user to the website and places the cell A2 value in webpage textbox. But my modification isnt doing the task.

What may be the reason for this?
Private Sub UserForm_Initialize()
Dim ie As Object, oDoc As Object
Dim ieForm As Variant
Dim WebBrowser1 As String

Set ie = WebBrowser1

Me. WebBrowser1 = "http://www.vbaexpress.com/forum/showthread.php?t=37494"

ie.Visible = True

ie.Navigate WebPage


Do Until ie.ReadyState = 4 'READYSTATE_COMPLETE
Loop

Set oDoc = ie.Document
Set ieForm = oDoc.forms(0)

ieForm(0).innerText = ActiveWorkbook.ActiveSheet.Range("A2").Text


Do Until ie.ReadyState = 4 'READYSTATE_COMPLETE
Loop
End Sub

Any help on this would be kindly appreciated.

Note: I hope my question remains the same from post to post.