[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 =\
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?
Re: [question] can i make a button that will open browser in new window?
vb Code:
Private Sub Button1_Click()
OpenSite ("Site here")
End Sub
Public Sub OpenSite(URL As String)
ShellExecute 0&, "Open", URL, 0&, 0&, vbNormalFocus
End Sub
That is probably what you are looking for hope it helps :)
Re: [question] can i make a button that will open browser in new window?
Quote:
Originally Posted by Hell-Lord
vb Code:
Private Sub Button1_Click()
OpenSite ("Site here")
End Sub
Public Sub OpenSite(URL As String)
ShellExecute 0&, "Open", URL, 0&, 0&, vbNormalFocus
End Sub
That is probably what you are looking for hope it helps :)
sub or function not defined =\
what the hell that means
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:
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.
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). ;)
Re: [question] can i make a button that will open browser in new window?
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
:wave:
Re: [question] can i make a button that will open browser in new window?
Or you could use
vb Code:
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate "your url here"
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. ;)
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
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.)
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.
:wave:
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. ;)
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.