我当前正在编写一个程序,允许用户选择一个父文件夹,该文件夹将充满子文件夹,每个子文件夹将充满不同的文件。我希望我的程序去查找一个每次都有相同名称格式的特定文件。
Sub PDFtoXL()
Application.ScreenUpdating = False
'Declarations
Dim ParentPath As String
Dim xlWkSh As Worksheet
Dim fso As Object, j As Long, folder1 As Object
'Parent Folder Selection
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Please select a parent folder."
.Show
End With
On Error Resume Next
'Find path to Parent Folder
ParentPath = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1) & "\"
Set xlWkSh = Application.ActiveSheet
xlWkSh.Cells(1, 1).Value = ParentPath
'Header
xlWkSh.Cells(2, 1).Resize(1, 10).Value = Array("Folder Name", "File Name", "Desginer", "Designer Date", "Design Check", "Design Check Date", "Stress", "Stress Date", "Design Authority Approval", "Design Authority Approval Date")
Set fso = CreateObject("Scripting.FileSystemObject")
'Getting Child Folder Name
Set folder1 = fso.GetFolder(ParentPath)
getSubFolder folder1
'Getting Proper File Name
'Getting Information from Proper File
'Layout
Call SortData
xlWkSh.Cells(2, 1).Resize(1, 3).EntireColumn.AutoFit
xlWkSh.Cells(2, 2).EntireColumn.AutoFit
xlWkSh.Cells(2, 3).EntireColumn.AutoFit
xlWkSh.Cells(2, 4).EntireColumn.AutoFit
xlWkSh.Cells(2, 5).EntireColumn.AutoFit
xlWkSh.Cells(2, 6).EntireColumn.AutoFit
xlWkSh.Cells(2, 7).EntireColumn.AutoFit
xlWkSh.Cells(2, 8).EntireColumn.AutoFit
xlWkSh.Cells(2, 9).EntireColumn.AutoFit
xlWkSh.Cells(2, 10).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, 1).Value = Array(SubFolder.Name)
Next SubFolder
For Each subfld In prntfld.SubFolders
getSubFolder subfld
Next subfld
End Sub
----------------------------------------------
Sub SortData()
Range("A3:J8").Sort _
Key1:=Range("A3"), Header:=xNo
End Sub
----------------------------------------------
现在这是我的文件夹的样子。 父级:ParentFolder 子代:ChildFolder1,ChildFolder2,... 文件:文件很多,但是我想找到“ ChildFolder1 SIGNOFF”,“ ChildFolder2 SIGNOFF”,...
如果任何人都可以确定该怎么做,那就太好了。现在,我只是希望能够进入该文件并打印其名称。
谢谢