簡體   English   中英

VBA - 在文件名中使用通配符來避免處理文件

[英]VBA - using a wild card in filename to avoid processing a file

我在 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

嘗試:

If Not fl.Name Like "*-Help-Me.xlsx" Then

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM