VB with Shell

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jayachandra
    New Member
    • Mar 2007
    • 49

    VB with Shell

    Hi to everybody,

    How to open the files otherthan .exe by using VB

    can any body tell with example please

    Thank u
  • Stwange
    Recognized Expert New Member
    • Aug 2007
    • 126

    #2
    In your declarations at the top of the code, paste:

    [CODE=vb]Public Declare Function ShellExecute Lib "shell32.dl l" Alias "ShellExecu teA" (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[/CODE]

    And then use this function:

    [CODE=vb]Public Function ShellExec(ByVal strFile As String)
    Dim x As Long: x = ShellExecute(0, "OPEN", strFile, "", "", 0)
    End Function[/CODE]
    Passing the filepath as a parameter.

    Hope that helps.
    Last edited by Killer42; Aug 17 '07, 03:45 AM. Reason: Added [CODE=vb] tag

    Comment

    • Stwange
      Recognized Expert New Member
      • Aug 2007
      • 126

      #3
      And the example you requested:

      Private Sub cmdOpen_Click()
      ShellExec("C:\t estfile.doc")
      End Sub

      Comment

      • pureenhanoi
        New Member
        • Mar 2007
        • 175

        #4
        Originally posted by Stwange
        In your declarations at the top of the code, paste:

        [CODE=vb]Public Declare Function ShellExecute Lib "shell32.dl l" Alias "ShellExecu teA" (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[/CODE]

        And then use this function:

        [CODE=vb]Public Function ShellExec(ByVal strFile As String)
        Dim x As Long: x = ShellExecute(0, "OPEN", strFile, "", "", 0)
        End Function[/CODE]
        Passing the filepath as a parameter.

        Hope that helps.
        Woa, that's very nice. Sometimes I would be called Shell excute function, but Shell command in VB can't archive parameters with space character.

        Comment

        Working...