It is quite simple to open a file using its default program (for example, if you double click a *.doc file in explorer, Word will automatically load. You do this using the ShellExecute function. This also allows you to open a browser with the specified URL, or an write a new email, to the specified email address:
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
'// open file (quotes are used so that the actual value that is passed is "C: est.doc"
Private Sub cmdOpen_Click()
If ShellExecute(0, vbNullString, """"C: est.doc"""",
vbNullString, vbNullString, vbNormalFocus) = 2 Then
End Sub
'// open url
Private Sub cmdOpen_Click()
If ShellExecute(0, vbNullString, "http://www.vbweb.f9.co.uk/",
vbNullString, vbNullString, vbNormalFocus) = 2 Then
End Sub
'// open email address
Private Sub cmdOpen_Click()
If ShellExecute(0, vbNullString, "mailto:[email protected]",
vbNullString, vbNullString, vbNormalFocus) = 2 Then
End Sub
Comments