0
我有.txt文件的文件夹:搜索excel列中的所有列,并检查文件夹中文件名的值以查看是否存在?
\\uksh000-file06\SharedAreas\1.0 Hewden Public\NS\Approval
每个文本文件中有一个随机的名字,像这样:
NS123SHS.txt
NSg234eH.txt
NSds3461.txt
大多数文件的文件名(减去extenstion .TXT)都在我在c栏的excel表格。
NS123SHS
NSds3461
我想扫描列c,检查文件名是否在我的文件夹目录中找到,如果是显示消息说找到,否则显示消息说找不到。
到目前为止,我所能弄清楚的是如何扫描我的列以获得特定的值,但是我希望能够扫描整个列,并比较每个值以查看它是否存在在我的文件夹?
有人可以告诉我我该怎么做吗?由于
Private Sub Workbook_Open()
Dim FindString As String
Dim Rng As Range
FindString = "NSds3461"
If Trim(FindString) <> "" Then
With Sheets("Home").Range("C:C") 'searches all of column A
Set Rng = .Find(What:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
MsgBox "found" 'value not found
Else
MsgBox "Reference Not Found" 'value not found
End If
End With
End If
看看了'Dir'功能。它将允许您在文件夹内搜索具有给定名称的文件。如果你想浏览整个专栏,你需要在Range中使用'For Each'循环来代替'Find'。 –