Open an External File, URL, Email and System Apps in VB6

6:18 AM Unknown 1 Comments

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://tutorpinoy.blogspot.com", vbNullString, vbNullString, vbNormalFocus

End Sub

'# Open email address
Private Sub cmdOpen_Click()

    ShellExecute 0, vbNullString, "mailto:tu2rpinoy@gmail.com", vbNullString, vbNullString, vbNormalFocus

End Sub

'#Open System Apps
Private Sub cmdOpen_Click()

    ShellExecute 0, vbNullString, "Notepad", vbNullString, vbNullString, vbNormalFocus

End Sub

1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete