Stacey
Stacey

Reputation: 5097

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

I am looping though a number of directories in VBA and am trying to avoid processing one file in each directory. The first two letters of the filename changes depending on the directory I am searching.

So for example in one directory the file would be called EE-Help-Me.xlsx and in another it would be called F-Help-Me.xlsx. I have tried to use the wildcard *-Help-Me but have obviously done something wrong as the file is processed. How can I fix this?

My code is:

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

Upvotes: 1

Views: 110

Answers (1)

transistor1
transistor1

Reputation: 2925

Try:

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

Upvotes: 5

Related Questions