我需要一个代码,以满足以下要求VBA要找到在A列的字符串中的特定文件夹中包含多种类型的文件
- 一个Excel工作表的列A包含一些字符串
- 我会指定文件夹搜索这些字符串
- 在指定的文件夹,将有子文件夹,以及多种类型的文件,例如:.TXT,.C,.XML等。
4,我需要搜索字符串一个接一个在整个fo lder连续结构和日志都喜欢在A列的howmany次数 搜索字符串在B档位置的文件(S)在C结果
谢谢
下面的代码将搜索文件名在列A和卖场进入在B中的位置
我尝试以下:
Explicit选项
Dim fso As New FileSystemObject
Dim i As Long
Dim fld As Folder
Dim c As Range
Sub Find_Path()
Dim nDirs As Long, nFiles As Long, lSize As Currency
Dim sDir As String, sSrchString As String, sItem As String
Dim fldr As FileDialog
111:
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = "D:\Check\" 'ActiveWorkbook.Path & "\"
.Show
If .SelectedItems.Count = 0 Then
MsgBox "Folder to search is not selected"
GoTo 111
Else
sDir = .SelectedItems(1)
End If
End With
MsgBox "You have selected : " & sDir, vbInformation
'Application.Cursor = xlWait
Application.DisplayStatusBar = True
Application.StatusBar = "Please wait..."
For Each c In Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
sSrchString = Range("A" & c.Row).Value
lSize = FindFile(sDir, sSrchString, nDirs, nFiles)
If Str(nFiles) = 0 Then
Range("B" & c.Row).Value = "Not Found in the Folder : " & sDir
End If
Next
Application.Cursor = xlDefault
Application.StatusBar = False
End Sub
This will search for files in folder and sub folders. but i need to search string
使用Google。这并不是您可以在不显示您尝试过的情况下询问代码的地方。 – Manu
对不起,它看起来像你没有做任何事情......所以,你的代码中缺少什么? – Manu
这里的代码只搜索我在列A中输入的文件(带有扩展名)。我想在每个文件中的一个路径下搜索它 –