Open URL in the default web browser
:confused:
I need help here. I'm making (something, I'm not going to tell you yet) and I have a Msgbox where if you click yes, I need it to open up the default web browser and to a specific web page. I need this answer in a few days. Any help will be appreciated and thanks in advance.
Re: Open URL in the default web browser
How about this.
vb 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
' Open the default browser on a given URL
' Returns True if successful, False otherwise
Public Function OpenBrowser(ByVal URL As String) As Boolean
Dim res As Long
' it is mandatory that the URL is prefixed with http:// or https://
If InStr(1, URL, "http", vbTextCompare) <> 1 Then
URL = "http://" & URL
End If
res = ShellExecute(0&, "open", URL, vbNullString, vbNullString, _
vbNormalFocus)
OpenBrowser = (res > 32)
End Function
Private Sub Command1_Click()
OpenBrowser ("www.vbforums.com")
End Sub
Re: Open URL in the default web browser
I think, following is more faster & easy.
vb Code:
'Private Declaration for the whole project
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
'Code for object that is showing msgbox, like Command1_Click event
Dim IntMsg As Integer
IntMsg = MsgBox("Do you wants to go at VbForums.Com ? ? ?", vbYesNo)
If IntMsg = vbYes Then
retValue = ShellExecute(Form1.hwnd, "Open", "http://www.vbforums.com", 0&, 0&, 0&)
End If