使用文件path列表中的VBA打开文件
我有一个文本文件中的Excel文件path列表(从VBAmacros输出)。
我如何使用vba打开这些文件?
谢谢
像这样会跳过无效的文件名/path
它打开存储在文本文件C:\temp\test.txt
中的任何有效工作簿,然后依次closures它们
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