Default browser:

How do I shell a user's default browser and go to a spacific page I specify?
Who is Participating?
MikeP090797Connect With a Mentor Commented:

Opening a browser to your homepage

You can use code like the following to open a browser to your homepage.
Modify filenames, paths, and URLs as necessary to match the values on your

Dim FileName As String, Dummy As String
Dim BrowserExec As String * 255
Dim RetVal As Long
Dim FileNumber As Integer
Const SW_SHOWNORMAL = 1 ' Restores Window if Minimized or

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

Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
(ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As _
String) As Long
'<Code> ---------

BrowserExec = Space(255)
FileName = "C:\temphtm.HTM"

FileNumber = FreeFile()     ' Get unused file number

Open FileName For Output As #FileNumber  ' Create temp HTML file
  Write #FileNumber, "<HTML> <\HTML>"  ' Output text
Close #FileNumber   ' Close file

' Then find the application associated with it.
  RetVal = FindExecutable(FileName, Dummy, BrowserExec)
  BrowserExec = Trim$(BrowserExec)
  ' If an application is found, launch it!
  If RetVal <= 32 Or IsEmpty(BrowserExec) Then ' Error

    Msgbox "Could not find a browser"

    RetVal = ShellExecute(frmMain.hwnd, "open", BrowserExec, _
      "", Dummy, SW_SHOWNORMAL)
    If RetVal <= 32 Then        ' Error
      Msgbox "Web Page not Opened"
    End If
  End If

Kill FileName  ' delete temp HTML file
Here is a *superior* one-line code!!!:

x = Shell("start")

Isn't it superior? :-)
If you like my code, can I have the points? (If you dont mind MikeP...).
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

rtcompAuthor Commented:
Exactly what I was looking for.

Which one of the two codes?
rtcompAuthor Commented:
Ok, they both did the same thing, kamall's code was less then MikeP. I allready execpted MikeP's answr but if you would like kamall I will resubmit a ? and then you can recive the same ammount of points also I no one objects.
rtcompAuthor Commented:
Ooooops, if no one objects?
Thank you very much rtcomp for your offer.
It will be very kind of you to do so.
Thanks again.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.