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
Bookmarks