答案 0 :(得分:4)
这样会跳过无效的文件名/路径
它会打开存储在文本文件C:\temp\test.txt
中的任何有效工作簿,然后依次关闭它们
Sub Alistair_Cooked()
Dim objFSO As Object
Dim objWB As Workbook
Dim strFN As String
Dim objTF As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTF = objFSO.OpenTextFile("C:\temp\test.txt")
On Error Resume Next
Do While Not objTF.AtEndOfStream
strFN = objTF.readline()
Set wb = Workbooks.Open(strFN)
If wb Is Nothing Then
Debug.Print strFN
Else
'do something
wb.Close False
Set wb = Nothing
End If
Loop
On Error GoTo 0
End Sub