Open browser from excel

  • Thread starter Thread starter nivek
  • Start date Start date
N

nivek

Is it possible to open a new instance of internet explorer with a command
button and pass it an address from an text box in excel? If so, can someone
please give an example of syntax?


TIA,
nivek
 
Hi nivek,

Yes. When the CommandButton "cmdGo" is clicked, the following code will
open an IE window and navigate to the URL entered in the TextBox "txtURL":

Private Sub cmdGo_Click()
On Error GoTo ErrHandler

ThisWorkbook.FollowHyperlink txtURL.Text

ExitRoutine:
Exit Sub
ErrHandler:
MsgBox "Invalid URL. Please try again.", _
vbExclamation, "Invalid URL"
Resume ExitRoutine
End Sub


Enter this code in the code behind the Worksheet which contains your
controls. To do that, just right-click the sheet tab and select View Code,
then copy/paste this code into the code window.


--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
 
from Posts by Jake Marx

If you go to the VBE and select Tools | References, look for Microsoft
Internet Controls and check the box next to it. That will allow Excel to
use the necessary library for the code to work as written.

Sub test23()
Dim ie As InternetExplorer

Set ie = New InternetExplorer

ie.Navigate URL:="http://www.longhead.com/"

Do While ie.Busy Or Not ie.ReadyState = _
READYSTATE_COMPLETE
DoEvents
Loop

MsgBox ie.Document.body.innertext

ie.Quit
Set ie = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top