-
Open WebPage
how to open a web page, in a new browser ??
i tried:
dim ret as string
ret = Shell("rundll32.exe url.dll,FileProtocolHandler " _
& "http://www.yahoo.com")
but if there is a browser already running, it uses it to open the url instead of opening the url in a new broser.
-
Code:
Private Declare Function ShellExecute Lib "shell32.dll" 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 Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Const HKEY_CLASSES_ROOT = &H80000000
Public Sub ShellNewBrowser(ByVal URL As String, Optional ByVal ShowWindowState As VbAppWinStyle = vbNormalFocus)
Dim lRegKey As Long
Dim sBrowser As String
Dim sData As String * 255
Dim lData As Long
If RegOpenKey(HKEY_CLASSES_ROOT, "htmlfile\shell\open\command", lRegKey) = 0 Then
lData = 255
Call RegQueryValueEx(lRegKey, "", 0&, 0&, ByVal sData, lData)
sBrowser = Left(sData, lData - 1)
Call RegCloseKey(lRegKey)
End If
Shell sBrowser & URL, ShowWindowState
End Sub
Usage:
ShellNewBrowser "http://www.yahoo.com", vbNormalFocus
-
dear matthew gates
i tried to run what u wrote and it didnt work, can u fix it?
-
Try this. Make a Form with a CommandButton and put the following code into it.
Code:
Private Declare Function ShellExecute Lib "shell32.dll" 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 Command1_Click()
'Open www.vb-world.net
Retval = ShellExecute(0&, vbNullString, "www.vb-world.net", vbNullString, "C:\", 1)
End Sub
-
Oh...you just wanted to open a url in a webbrowser? Not open a new window everytime? Sorry bout that..misunderstood.
-
to matthew gates
i did want in a n e w webbrowser
the problem is that i tried what you worte to me at first and it didnt work at all, so can u check it again?
-
to matthew gates
it gives me error 53, file not found
-
I could swear i already answered to this post...but here goes again...
Code:
Dim IE As Object
Set IE = CreateObject("internetexplorer.application")
IE.Visible = True
IE.Navigate(Text1.Text)
it will open a new browser with the url taken from text1.text.
Hope that's what you were looking for,
D!m
-
to dim:
it doesnt work with netscape
-
And there's your answer brucelee. Perhaps it doesn't detect IE?