Results 1 to 4 of 4

Thread: ShellExecute - Dbclick() in a ListBox

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2000
    Location
    Oporto - Portugal
    Posts
    16

    Cool ShellExecute - Dbclick() in a ListBox

    Hi

    i´m traing to open a file by dbclicking in listbox but....nothing
    Here´s the code i used


    [code]
    Public 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

    Public Const SW_SHOWNORMAL = 1


    Public Sub Open_file_Excel()
    Dim OK As Long
    OK = ShellExecute(0&, vbNullString, "Excel", vbNullString, "c:\", SW_SHOWNORMAL)
    End Sub
    [code]


    If i dbclick in a file it opens the excel but not the file...so there´s some parameters that open any file??


    Thanks

  2. #2
    Addicted Member
    Join Date
    Jul 1999
    Location
    St-Élie d'Orford, Quebec, Canada
    Posts
    133
    Hi,

    if what you are trying to do is start Excel and load a file into it then use the Shell FUNCTION like this :

    Shell "Path to the exe" & " " & "Path to the file", vbMaximizedFocus

    Should give you something like :

    Shell "C:\Excel.exe MyDoc.xls", vbMaximizedFocus

    NOTE : ALL of the paths must be in short path format so use the API call GetShortPathName...


    Hope thats what you wanted...

  3. #3
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Assuming you use a filelistbox for this, this should work.
    Code:
    Option Explicit
    
    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
    Private Const SW_SHOWNORMAL = 1
    
    Private Sub File1_DblClick()
    Dim retVal As Long
    Dim Path As String
        Path = File1.Path
        If Right(Path, 1) <> "\" Then Path = Path & "\"
        retVal = ShellExecute(Me.hwnd, "Open", Path & File1.FileName, vbNullString, Path, SW_SHOWNORMAL)
    End Sub

  4. #4

    Thread Starter
    Junior Member
    Join Date
    May 2000
    Location
    Oporto - Portugal
    Posts
    16

    Thanks Booth

    Originally posted by Frans C
    Assuming you use a filelistbox for this, this should work.
    Code:
    Option Explicit
    
    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
    Private Const SW_SHOWNORMAL = 1
    
    Private Sub File1_DblClick()
    Dim retVal As Long
    Dim Path As String
        Path = File1.Path
        If Right(Path, 1) <> "\" Then Path = Path & "\"
        retVal = ShellExecute(Me.hwnd, "Open", Path & File1.FileName, vbNullString, Path, SW_SHOWNORMAL)
    End Sub
    It works !!! Thanks Frans C and Vince

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width