|
模块中
- Public arr$(), m&
- Sub Start()
- Dim Fso As Object, Folder As Object
- Set Fso = CreateObject("Scripting.FileSystemObject")
- Set Folder = Fso.GetFolder(ThisWorkbook.Path)
- Call GetFiles(Folder)
- Sheet1.ComboBox1.Clear
- m = 0
- Set Folder = Nothing
- Set Fso = Nothing
- End Sub
- Sub GetFiles(ByVal Folder As Object)
- Dim SubFolder As Object
- Dim File As Object
- For Each File In Folder.Files
- If File.Name Like "*.xlsx" Then
- If InStr(File.Name, ThisWorkbook.Name) = 0 Then
- m = m + 1
- ReDim Preserve arr(1 To m)
- arr(m) = Replace(File, ThisWorkbook.Path, "")
- End If
- End If
- Next
- For Each SubFolder In Folder.SubFolders
- Call GetFiles(SubFolder)
- Next
- End Sub
复制代码
Sheet1代码编辑区
- Private Sub ComboBox1_Change()
- If ComboBox1.ListIndex = -1 Then
- Dim brr$(), i&, m&
- On Error Resume Next
- If UBound(arr) < 0 Then Call Start
- ReDim brr(1 To UBound(arr))
- For i = 1 To UBound(arr)
- If InStr(arr(i), ComboBox1.Value) Then
- m = m + 1
- brr(m) = arr(i)
- End If
- Next
- If m > 0 Then
- ReDim Preserve brr(1 To m)
- ComboBox1.List = brr
- Else
- ComboBox1.Clear
- End If
- End If
- End Sub
复制代码 |
|