Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a web browser from vb

Status
Not open for further replies.

zggs90

Programmer
Sep 3, 2001
58
GB
I am writing a VB program that is required to open the web browser and display a site that is selected from a drop down list. I use the code below, where strName is the name from the dropdown list:

Dim strURL
Dim strName

strName = "
strURL = Shell("C:\Program Files\Internet Explorer\" _
& "Iexplore.exe " & strName)

When I execute the program the browser opens but is minimised - how do I maximise the browser automatically?
 
The Shell function has an optional second parameter WindowStyle. Set this parameter to vbMaximizedFocus:

strURL = Shell("C:\Program Files\Internet Explorer\" _
& "Iexplore.exe " & strName, vbMaximizedFocus)

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Another way to do it is to use the dll that's intended for this purpose, shdocvw.dll. You get a great deal of control over the instance of IE if you use this. Set a reference in VB to Microsoft Interenet Controls. The essential code is:
Code:
Dim ie As InternetExplorer
Set ie = New InternetExplorer
ie.Navigate "[URL unfurl="true"]www.microsoft.com"[/URL]
ie.Visible = True
You'll find that there are lots of other methods and properties to control what shows and what doesn't. For example, ie.StatusBar = False will prevent the status bar from showing.

Bob
 
Bob, thanks for your help.

But I get an error on the line "Set ie = New InternetExplorer"

Error is "Class does not support Automation or does not support expected interface"

Any advice please

Thanks
 
Here is the easiest was of solving your problem.


General
Public ie As Integer
_______________________________________
Private Sub Command1_Click()
ie = Shell("c:\programme\internet explorer\iexplore.exe vbMaximizedFocus)

End Sub

just change the address as desired. Instead of cmd buttom u can use various things(timers ect)
 
Another Info:
Dont forget to change directoy name urs will be program files.
 
If you take a closer look at it its not the same. you don't have to define strName nor do u have to insert the &strName etc. its to complicated. This is the Easiest way. no xtras just write the desired url right after the file you want to open.
 
This is how I do it, hope it helps.

Private Declare Function ShellExecute Lib "shell32" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Sub cmdTransfer_Click()
Dim l_lngRetVal As Long

Const SW_SHOWNORMAL = 1
l_lngRetVal = ShellExecute(0&, vbNullString, " vbNullString, _
"C:\", SW_SHOWNORMAL)
 
I dunno, that's what I do, and it works for me. Maybe the way the other folks are showing you will work better for you.

Bob
 
try...
Code:
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "[URL unfurl="true"]http://www.yahoo.com/"("InternetExplorer.Application")[/URL]

;-)

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
AND to go one step further ;-)

Code:
Sub OpenURL(URL As String)
  Dim IE As Object
  Set IE = CreateObject("InternetExplorer.Application")
  IE.Visible = True
  IE.Navigate URL
End Sub

Oops... (there was a typo in the above code as well [neutral])

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
The simple solution that runs on the default browser:
Code:
Shell "RUNDLL32.EXE URL.DLL, FileProtocolHandler [URL unfurl="true"]www.essexsteam.co.uk"[/URL] , vbNormalFocus

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top