Sub Main()
Dim FSO As New FileSystemObject
Dim Fl As File
Dim Folder As Folder
Dim F_Name, F_Path As String
F_Path = ThisWorkbook.Path & "\"
Set Folder = FSO.GetFolder(F_Path)
F_Name = "CI*.*"
For Each Fl In Folder.Files
If Fl.Name = F_Name Then
GoTo Report
End If
Next
Report:
Workbooks.Open Filename:=F_Path & F_Name
我想打開一個具有相同位置的excel文件,但我只知道文件名的一部分,所以請幫助我如何打開文件名。謝謝!VBA FILE搜索
你必須使用Dir函數通過通配符來打開文件。 http://www.techonthenet.com/excel/formulas/dir.php –
嘗試改變'如果Fl.Name = F_Name然後'爲'如果Fl.Name像F_Name那麼' – Fadi
這個答案將幫助你通過它http://stackoverflow.com/questions/19527415/using-a-wildcard-to-open-an-excel-workbook –