Dim objOpenBrowser As clsOpenBrowser
Set objOpenBrowser = New clsOpenBrowser
objOpenBrowser.OpenBrowser Me.hWnd, strLink
'Add to New Class Module and call it clsOpenBrowser
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hWnd As Long, ByVal lpszOp As _
String, ByVal lpszFile As String, ByVal lpszParams As String, _
ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
Private Declare Function FindExecutable Lib "shell32.dll" Alias _
"FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As _
String, ByVal lpResult As String) As Long
Const SW_SHOWNORMAL = 1
Const SE_ERR_FNF = 2&
Const SE_ERR_PNF = 3&
Const SE_ERR_ACCESSDENIED = 5&
Const SE_ERR_OOM = 8&
Const SE_ERR_DLLNOTFOUND = 32&
Const SE_ERR_SHARE = 26&
Const SE_ERR_ASSOCINCOMPLETE = 27&
Const SE_ERR_DDETIMEOUT = 28&
Const SE_ERR_DDEFAIL = 29&
Const SE_ERR_DDEBUSY = 30&
Const SE_ERR_NOASSOC = 31&
Const ERROR_BAD_FORMAT = 11&
Public Sub OpenBrowser(ByVal hWnd As Long, ByVal strInternetAddress As String)
Dim FileName, Dummy As String
Dim BrowserExec As String * 255
Dim retVal As Long
Dim FileNumber As Integer
' First, create a known, temporary HTML file
BrowserExec = Space(255)
FileName = App.Path & "\temphtm1.HTM"
FileNumber = FreeFile
Open FileName For Output As #FileNumber
Write #FileNumber, "<HTML> <\HTML>"
Close #FileNumber
' 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 associated Browser", vbExclamation, _
"Browser Not Found"
Else
retVal = ShellExecute(hWnd, "open", BrowserExec, _
strInternetAddress, Dummy, SW_SHOWNORMAL)
If retVal <= 32 Then
MsgBox "Web Page not Opened", vbExclamation, "URL Failed"
End If
End If
Kill FileName
End Sub