一个曾多次提的问题(在VBA中实现Drive,File功能),我做了一个,希望各位完善!
'在userform中增加如下控件:ComboBox,CommandButton,ListBox(2个),Label
代码如下:
Dim vbdir As New FileSystemObject
Dim vbfloder As Folder
Private Sub ComboBox1_Change()
Call changedir(ComboBox1.Text + ":\")
End Sub
Private Sub CommandButton2_Click()
If Not vbfloder.IsRootFolder Then
Set vbfloder = vbdir.GetFolder(vbfloder.ParentFolder.Path)
Call changedir(vbfloder.Path)
End If
End Sub
Private Sub ListBox1_Click()
Call changedir(vbfloder.Path + "\" + ListBox1.Text)
End Sub
Private Sub UserForm_Initialize()
ComboBox1.Clear
For Each a In vbdir.Drives
ComboBox1.AddItem a.DriveLetter
Next
Label1.Caption = ""
End Sub
Public Sub changedir(path1 As String)
Set vbfloder = vbdir.GetFolder(path1)
ListBox1.Clear
ListBox2.Clear
For Each b In vbfloder.SubFolders
ListBox1.AddItem (b.Name)
Next
For Each b In vbfloder.Files
ListBox2.AddItem (b.Name)
Next
Label1.Caption = vbfloder.Path
End Sub
以上程序可实现主要功能,但感觉不太完美,希望各位帮忙完善!谢谢!