1
The ShellExecute function allows you to open external application, specific URL location, email address or launch system applications upon clicking on a single button.

1. Start a new Standard Exe Project.
2. Add this code in General Declarations.
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
3. Add a command button on your form, change its name to cmdOpen.
4. DoubleClick on the form and try any of the codes below.


'# Open file (quotes are used so that the actual value that is passed is "C:\test.txt"
Private Sub cmdOpen_Click()
    ShellExecute 0, vbNullString, """"C:\test.txt"""", vbNullString, vbNullString, vbNormalFocus
End Sub
'# Open url
Private Sub cmdOpen_Click()
    ShellExecute 0, vbNullString, "http://omelsoft.blogspot.com", vbNullString, vbNullString, vbNormalFocus
End Sub
'# Open email address
Private Sub cmdOpen_Click()
    ShellExecute 0, vbNullString, "mailto:omelsoft@gmail.com", vbNullString, vbNullString, vbNormalFocus
End Sub
'#Open System Apps
Private Sub cmdOpen_Click()
    ShellExecute 0, vbNullString, "Notepad", vbNullString, vbNullString, vbNormalFocus
End Sub

Post a Comment

  1. Very nice tutorial' Keep up the good work

    ReplyDelete

 
Top