よくわからんが、単純に If right(filename, 4) = ".txt" Then じゃダメなんかい