Results 1 to 3 of 3

Thread: Open URL in the default web browser

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Location
    Canada
    Posts
    23

    Open URL in the default web browser



    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.

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Open URL in the default web browser

    How about this.

    vb Code:
    1. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    2.     (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
    3.     ByVal lpParameters As String, ByVal lpDirectory As String, _
    4.     ByVal nShowCmd As Long) As Long
    5.  
    6. ' Open the default browser on a given URL
    7. ' Returns True if successful, False otherwise
    8.  
    9. Public Function OpenBrowser(ByVal URL As String) As Boolean
    10.     Dim res As Long
    11.    
    12.     ' it is mandatory that the URL is prefixed with http:// or https://
    13.     If InStr(1, URL, "http", vbTextCompare) <> 1 Then
    14.         URL = "http://" & URL
    15.     End If
    16.    
    17.     res = ShellExecute(0&, "open", URL, vbNullString, vbNullString, _
    18.         vbNormalFocus)
    19.     OpenBrowser = (res > 32)
    20. End Function
    21.  
    22. Private Sub Command1_Click()
    23. OpenBrowser ("www.vbforums.com")
    24. End Sub
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3
    Addicted Member Mehmood Iqbal's Avatar
    Join Date
    Mar 2011
    Location
    Chakwal, Pakistan
    Posts
    150

    Re: Open URL in the default web browser

    I think, following is more faster & easy.

    vb Code:
    1. 'Private Declaration for the whole project
    2.  
    3. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    4. (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
    5. ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) _
    6. As Long
    7.  
    8. 'Code for object that is showing msgbox, like Command1_Click event
    9.  
    10.   Dim IntMsg As Integer
    11.   IntMsg = MsgBox("Do you wants to go at VbForums.Com ? ? ?", vbYesNo)
    12.  
    13.   If IntMsg = vbYes Then
    14.   retValue = ShellExecute(Form1.hwnd, "Open", "http://www.vbforums.com", 0&, 0&, 0&)
    15.  
    16.   End If
    Last edited by Mehmood Iqbal; Apr 11th, 2011 at 04:27 AM. Reason: Code Edited

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width