VBAのDir()関数のワイルドカードの誤動作を補正する。
If Like で補正します。
Dim File As String
Dim Folder As String
Dim Pattern1 As String
Dim Pattern2 As String
Folder = "c:\windows\system32"
If Right(Folder, 1) <> "\" Then Folder = Folder & "\"
Pattern1 = "*.txt"
Pattern2 = Replace(Replace(Pattern1, "[", "[[]"), "#", "[#]")
File = Dir(Folder & Pattern1)
Do While Len(File)
If File Like Pattern2 Then
Debug.Print File
Else
Debug.Print "!", File
End If
File = Dir()
Loop