Okedoke... 我有一个 Excel 电子表格,其 A 列中有一个文件名。A 列中列出的文件名出现在一个或多个源目录中的一个或多个文本文件中。
我需要 Excel 递归搜索文本文件,并将包含 A 列中指定的文件名的文件的路径返回到 B 列。如果多个文件转到 C 列等。
Excel工作表将是
__________________________________
__|______A___________|______B_____|
1 | filename.avi | |
2 | another_file.flv | |
要搜索的文本文件将位于 C:\WebDocs\ 下的多个目录中,并且是 DokuWiki 页面,有些非常短,例如需要返回的页面
===== Problem Description =====
Reopen a closed bank reconciliation.
===== Solution =====
Demonstration of the tool box routine that allows reposting of the bank rec.
{{videos:bank_rec_reopen1006031511.flv|}}
===== Additional Information -cm =====
You may have noticed that in the video there is a number to the right of the bank account number. In this case it was a 0. That indicates department 0 which is all departments. You get the department 0 if you have all departments combined using the option in the bank set up called "One Bank for All Departments". If this setting is not checked then when you create your starting bank rec for each department you will get a 1 to the right of the bank rec for department 1 and so on. You should normally only have a 0, or have numbers 1 or greater. If you have both, then the method was changed after the initial bank rec was made. You just have to be aware of this as you move forward. As always backup before you make any changes.
还有一些其他页面虽然很长,但不包含视频,但会在正在搜索的目录中。格式相同,纯文本,==== 是标题的占位符,可能包含指向其他页面/站点的链接。
我确实找到了一个现有的 VBA 脚本,它可以满足我的需要。它不会递归并返回太多信息,例如日期/时间戳,我需要的只是路径。
Private Sub CommandButton1_Click()
Dim sh As Worksheet, rng As Range, lr As Long, fPath As String
Set sh = Sheets(1) 'Change to actual
lstRw = sh.Cells.Find(What:="*", After:=sh.Range("A1"), LookAt:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row
Set rng = sh.Range("A2:A" & lstRw)
With Application.FileDialog(msoFileDialogFolderPicker)
.Show
fPath = .SelectedItems(1)
End With
If Right(fPath, 1) <> "\" Then
fPath = fPath & "\"
End If
fwb = Dir(fPath & "*.*")
x = 2
Do While fwb <> ""
For Each c In rng
If InStr(LCase(fwb), LCase(c.Value)) > 0 Then
Worksheets("Sheet2").Range("C" & x) = fwb
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(fwb)
Worksheets("Sheet2").Range("D" & x) = f.DateLastModified
Worksheets("Sheet2").Range("B" & x) = f.Path
Worksheets("sheet2").Range("A" & x) = c.Value
Columns("A:D").AutoFit
Set fs = Nothing
Set f = Nothing
x = x + 1
End If
Next
fwb = Dir
Loop
Set sh = Nothing
Set rng = Nothing
Sheets(2).Activate
End Sub
到目前为止,我的修改尝试通常导致脚本损坏,因此导致我在这里寻求帮助。
谢谢,
西蒙