Option Explicit


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

Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long

Const SW_SHOWNORMAL = 1
Const SE_ERR_NOASSOC = 31
Const ERROR_FILE_NOT_FOUND = 2&
Const WM_CLOSE = &H10

Sub OpenAnyFile()
Dim strVisio As String
Dim strChm As String
Dim strMail As String
Dim lngRet As Long
Dim Msg As String

'// //
'// Example strings //
'// //

'// Open a Visio File
strVisio = "C:\VisioFiles\WIP\MyDrawing.VSD"

'// Open a chm Help file
strChm = "C:\WINDOWS\HELP\msoe.chm"

'// Open up default Mailer
strMail = "mailto:ivanmoala@xtra.co.nz"
'

'// Note: You don't have to specify the "open" command
'// by default Shell will default to open if you use
'// vbNullString, "Open" is just used for clarity.
lngRet = ShellExecute( _
0, _
"Open", _
strChm & vbNullString, _
vbNullString, _
vbNullString, _
SW_SHOWNORMAL)

Select Case lngRet
Case SE_ERR_NOASSOC
Msg = " is NOT Associated with any Application!"
Case ERROR_FILE_NOT_FOUND
Msg = " could NOT be found!"
End Select

MsgBox lngRet
SendMessage lngRet, WM_CLOSE, 0, 0

If Len(Msg) = 0 Then Exit Sub

MsgBox strVisio & Msg


End Sub