目前我有一个包含许多文件夹的文件夹
示例:
A01
A02
A03
A04
B01
B02
B03
当我在范围B3中输入“A”时,我只需要文件夹A01到A04,所以当我输入“B”时,只会显示文件夹B01到B03。文件夹名称和文件夹路径是否可以显示在清单中?在按下“确定”后,只有被勾选的文件夹将被处理(我有其他代码来处理数据)/导入。
Sub FolderNames()
Application.ScreenUpdating = False
Dim xPath As String
Dim xWs As Worksheet
Dim fso As Object, j As Long, folder1 As Object
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Choose the folder"
.Show
End With
On Error Resume Next
xPath = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1) &
"\"
'Application.Workbooks.Add
Set xWs = Application.ActiveSheet
xWs.Cells(1, 1).Value = xPath
xWs.Cells(2, 1).Resize(1, 2).Value = Array("Path", "Name")
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder1 = fso.getFolder(xPath)
getSubFolder folder1
xWs.Cells(2, 1).Resize(1, 2).Interior.Color = RGB(194, 244, 238)
xWs.Cells(2, 1).Resize(1, 2).EntireColumn.AutoFit
Application.ScreenUpdating = True
End Sub
Sub getSubFolder(ByRef prntfld As Object)
Dim SubFolder As Object
Dim subfld As Object
Dim xRow As Long
For Each SubFolder In prntfld.SubFolders
xRow = Range("A1").End(xlDown).Row + 1
Cells(xRow, 1).Resize(1, 2).Value = Array(SubFolder.Path, SubFolder.Name)
Next SubFolder
End Sub
这是我目前的代码,它将显示单元格中的所有文件夹名称和文件夹路径,但不显示清单。 任何帮助和建议表示赞赏。 谢谢!
答案 0 :(得分:0)
如何放一些' x'在您想要处理的行上,然后添加一个表单(如圆形或正方形),然后右键单击它然后"链接到一个宏" (法语" Affecter une macro")。 这个宏应该解析' x'并按照路径完成工作。
如果你真的想要更具视觉效果的东西,请在treeview中查看userform等,他们可以使用CheckBox。 (添加控件Microsoft treeview Control,版本Xx)