2013-12-12 29 views
1

它的標題很簡單。我需要能夠打開具有「x .xlsx」但不包含「* xy.xlsx」的文件夾的文件。使用特定的通配符打開此目錄中的所有文件

只是不知道該怎麼做。我可以得到文件目錄,然後用星號選擇帶有「x」的所有文件。但我有文件,我不想打開,唯一的變化是在文件名的末尾有少量文本(「y」)。

這是我到目前爲止。我會補充什麼。

Workbooks.Open (Dir & FileNameStart & "*") 

希望這一點很清楚。

+0

問題標題與問題不一致。編輯。 – brettdj

回答

6
Dim f 

f = Dir(SrcPath & "*x*.xlsx", vbNormal) 
Do While Len(f)>0 
    If not f like "*y.xlsx" Then 
     Workbooks.open SrcPath & f 
     '... 
    end if 
    f = Dir() 
Loop 
+0

+ 1不錯。 :) –

+0

+1覆蓋。 – brettdj

0

你的問題還有些不清楚。然而看看下面的可能的解決方案:

Dim tmp 

'this will run inside loop- so, start your loop somewhere here 
tmp = Dir() 
'if file name has "y" and has no "yyx" then... 
If InStr(1, tmp, "y", vbTextCompare) <> 0 And _ 
    InStr(1, tmp, "yyx", vbTextCompare) = 0 Then 

    '...you will open it 
    Workbooks.Open tmp 

End If 

因此,把它放在你的循環,它應該工作。

相關問題