Results 1 to 15 of 15

Want to open selected file from listbox (Userform)

Threaded View

  1. #1
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Want to open selected file from listbox (Userform)

    HI,
    I want to update below code to openable file from listbox,

    i want to open selected file using commandbutton1

    For userform code
    Private Sub TextBox1_Change()
    Dim i As Long
        Dim sFind As String
         
       sFind = Me.TextBox1.Text
         
       If Len(sFind) = 0 Then
            Me.ListBox1.ListIndex = -1
            Me.ListBox1.TopIndex = 0
        Else
            For i = 0 To Me.ListBox1.ListCount - 1
              If UCase(Left(Me.ListBox1.List(i), Len(sFind))) = UCase(sFind) Then
                    Me.ListBox1.TopIndex = i
                    Me.ListBox1.ListIndex = i
                    Exit For
                End If
            Next i
    End If
    End Sub
    
    Private Sub UserForm_Initialize()
        
        Dim FileList    As Variant
        Dim Search_All  As Long
        
            ReDim FileList(0)
            Search_All = -1
            
     Call FindFiles("Z:\42766\Jan 2 Dec 2014\1.12.16\", "*.xlsm", FileList, Search_All)
    
            
            ListBox1.List = Application.Transpose(FileList)
    
    End Sub
    in module

    Private oShell  As Object
    
    Sub FindFiles(ByVal FolderPath As Variant, ByVal FileFilter As String, ByRef FileList As Variant, Optional ByVal SubfolderLevel As Long)
    
        Dim n           As Long
        Dim oFile       As Object
        Dim oFiles      As Object
        Dim oFolder     As Variant
        Dim oShell      As Object
            
            If oShell Is Nothing Then
                Set oShell = CreateObject("Shell.Application")
            End If
            
            Set oFolder = oShell.Namespace(FolderPath)
                If oFolder Is Nothing Then
                    MsgBox "The Folder '" & FolderPath & "' Does Not Exist.", vbCritical
                    SearchSubFolders = False
                    Exit Sub
                End If
                
            Set oFiles = oFolder.Items
                
                oFiles.Filter 64, FileFilter
                    For Each oFile In oFiles
                        n = UBound(FileList)
                        FileList(n) = oFile.Name    ' for getting full path with file name add (oFile.Path)
                        ReDim Preserve FileList(n + 1)
                    Next oFile
    
                oFiles.Filter 32, "*"
                    If SubfolderLevel <> 0 Then
                        For Each oFolder In oFiles
                            Call FindFiles(oFolder, FileFilter, FileList, SubfolderLevel - 1)
                        Next oFolder
                    End If
                    
    End Sub
    Attached Files Attached Files
    Use Code-Tags for showing your code :
    Please mark your question Solved if there has been offered a solution that works fine for you
    If You like solutions provided by anyone, feel free to add reputation using STAR *

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Userform Listbox that populates the userform when selected
    By retroboy17 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-12-2015, 07:56 PM
  2. [SOLVED] Add Selected Items From One ListBox to Another ListBox on UserForm
    By EnigmaMatter in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-27-2014, 06:53 PM
  3. select a item in userform listbox to open a file
    By simeonmein in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-17-2013, 09:36 AM
  4. Put a selected row into a listbox in a userform
    By sebastienkanj in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-09-2013, 08:23 AM
  5. VBA - Populate Listbox based on value selected in another ListBox (On Userform)
    By raaboo in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-12-2012, 11:18 AM
  6. Populate userform listbox based on value selected in another listbox
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-07-2012, 05:16 PM
  7. Display a UserForm based on Data selected in another UserForm's ListBox
    By RPhilbin83 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-26-2011, 11:35 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1