我在 VBA 中循环遍历多个目录,并试图避免在每个目录中处理一个文件。文件名的前两个字母根据我搜索的目录而变化。
例如,在一个目录中,该文件将被称为 EE-Help-Me.xlsx,而在另一个目录中,它将被称为 F-Help-Me.xlsx。我曾尝试使用通配符 *-Help-Me,但在处理文件时显然做错了。我怎样才能解决这个问题?
我的代码是:
Sub ListFiles(fld As Object, Mask As String)
Dim fl As Object 'File
For Each fl In fld.Files
If fl.Name Like Mask Then
'open and interrogate file here
If fl.Name <> "*-Help-Me.xlsx" Then '<<-- not catching when the offending file is present
Debug.Print fld.Path & "\" & fl.Name
'Do something
End If
End If
Next
End Sub
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
89 次 |
| 最近记录: |