Results 1 to 15 of 15

Thread: [question] can i make a button that will open browser in new window?

  1. #1

    Thread Starter
    Addicted Member Incures's Avatar
    Join Date
    May 2006
    Location
    south afrika
    Posts
    205

    [question] can i make a button that will open browser in new window?

    as my title says,
    ther is way to make a button that will open browser?
    out side of the program.

    if ther is how do i do it =\

  2. #2
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [question] can i make a button that will open browser in new window?

    A particular page as well? Or just open up the browser?

  3. #3
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [question] can i make a button that will open browser in new window?

    vb Code:
    1. Private Sub Button1_Click()
    2. OpenSite ("Site here")
    3. End Sub
    4.  
    5. Public Sub OpenSite(URL As String)
    6. ShellExecute 0&, "Open", URL, 0&, 0&, vbNormalFocus
    7. End Sub

    That is probably what you are looking for hope it helps

  4. #4

    Thread Starter
    Addicted Member Incures's Avatar
    Join Date
    May 2006
    Location
    south afrika
    Posts
    205

    Re: [question] can i make a button that will open browser in new window?

    Quote Originally Posted by Hell-Lord
    vb Code:
    1. Private Sub Button1_Click()
    2. OpenSite ("Site here")
    3. End Sub
    4.  
    5. Public Sub OpenSite(URL As String)
    6. ShellExecute 0&, "Open", URL, 0&, 0&, vbNormalFocus
    7. End Sub

    That is probably what you are looking for hope it helps
    sub or function not defined =\
    what the hell that means

  5. #5
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: [question] can i make a button that will open browser in new window?

    Add the ShellExecute API function declaration to the very top of your code (under Option Explicit if it's there).

    vb Code:
    1. 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

    Also make sure you have a command button on the form named "Button1" when testing the code.

  6. #6
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: [question] can i make a button that will open browser in new window?

    Topic says can i make a button that will open browser in new window?

    The ShellExecute API will just keep opening the default browser with a new URL. If you right-click on a link you can use Open in New Window. How do you get ShellExecute to open in a new window?

    Lets say you have a ListBox with URL's added and everytime you click on the ListBox it opens a new window to that List1.Text (URL).
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  7. #7
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: [question] can i make a button that will open browser in new window?

    IIF(Post.Rate > 0 , , )

  8. #8
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: [question] can i make a button that will open browser in new window?

    ok came with a solution

    Make a reference to Microsoft Internet Controls

    put this in a module
    Public ie2() As InternetExplorer

    in your form use like this


    Code:
    Private Sub Form_Load()
        ReDim ie2(0)
    End Sub
    
    Private Sub Command3_Click()
        ReDim Preserve ie2(UBound(ie2) + 1)
        Set ie2(UBound(ie2)) = CreateObject("InternetExplorer.Application")
       ie2(UBound(ie2)).Visible = True
       ie2(UBound(ie2)).Navigate2 "http://www.vbforums.com/"
    End Sub
    IIF(Post.Rate > 0 , , )

  9. #9
    Hyperactive Member Ambivalentiowa's Avatar
    Join Date
    Apr 2002
    Location
    Coming soon to a store near you!
    Posts
    375

    Re: [question] can i make a button that will open browser in new window?

    Or you could use

    vb Code:
    1. Dim ie As Object
    2. Set ie = CreateObject("InternetExplorer.Application")
    3. ie.Visible = True
    4. ie.navigate "your url here"
    -Show me on the doll where the music touched you.

  10. #10
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: [question] can i make a button that will open browser in new window?

    Thanks guys.

    zeezee's link only says to reference Microsoft Internet Controls in your project, which I've done (Microsoft Internet Controls, Shdocvw.dll) but I get a Type Mismatch error here

    Set ie1 = CreateObject("InternetExplorer.Application")

    I've tried Dim ie1 As InternetExplorer and Dim ie1 As WebBrowser but I still get the same error.

    zeezee's other example gives me the exact same error in

    Set ie2(UBound(ie2)) = CreateObject("InternetExplorer.Application")

    Ambivalentiowa example works for the first URL and when you click the button again the web page shows in a new window but there are no objects on the page, its a blank page.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  11. #11
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: [question] can i make a button that will open browser in new window?

    Using shellexecute you can open a new browser this way.
    Code:
    Option Explicit
    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
    Const SW_SHOWNORMAL = 1
    
    Private Sub Command1_Click()
        ShellExecute Me.hwnd, "Open", "IExplore.exe", "http://www.dell.com", "C:\", SW_SHOWNORMAL
    End Sub

  12. #12
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: [question] can i make a button that will open browser in new window?

    It should be the Reference, not the components. Its the same DLL, but it should be referenced. (I dont know why its acting like that.)
    IIF(Post.Rate > 0 , , )

  13. #13
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: [question] can i make a button that will open browser in new window?

    Quote Originally Posted by Keithuk
    Ambivalentiowa example works for the first URL and when you click the button again the web page shows in a new window but there are no objects on the page, its a blank page.
    What Ambivalentiowa has said is without using the reference , you can do my example , but you have to declare the ie2 as object.
    IIF(Post.Rate > 0 , , )

  14. #14
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: [question] can i make a button that will open browser in new window?

    Quote Originally Posted by zeezee
    It should be the Reference, not the components. Its the same DLL, but it should be referenced. (I dont know why its acting like that.)
    Ok I removed the WebBroswer control and just referenced Shdocvw.dll and it worked without an error. But when I closed the IE windows it throws up a 462 error The remote server machine does not exist or is unavailable. That happens in the

    Debug.Print "ie busy " & CStr(i * 0.1) & " seconds with ReadyState " & ie1.ReadyState

    I've tried all of the three different way and they all work. The problem must have been the reference to Shdocvw.dll and not the control.

    Thanks guys, thats a great help.

    I wonder if Incures has ever been back to check on his post? His original question was can i make a button that will open browser in new window?. With him saying new window I thought he was having the same problem.

    MarkT I know what ShellExecute does I've used it for years. I was wondering if you could ShellExecute a new window but it doesn't.

    Thanks again for you help.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  15. #15
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: [question] can i make a button that will open browser in new window?

    Quote Originally Posted by Keithuk
    MarkT I know what ShellExecute does I've used it for years. I was wondering if you could ShellExecute a new window but it doesn't.

    Thanks again for you help.
    Have you tried the code I posted? Unless I don't understand what you mean by ShellExecute a new window this should work. It doesn't reuse a currently open window.

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