把下面修改成遍歷當前目錄,而不是子目錄,還有就是如何自動加載宏
Sub test()
Dim mPath As String, fA As String, mAry(1 To 1000), k As Integer, i As Integer, wb As Workbook
On Error Resume Next
If Workbooks.Count > 1 Then
MsgBox "關閉其他工作簿!": Exit Sub
'----------設置父文件夾路徑-----
mPath = "D:\Project overview 2015"
fA = Dir(mPath & "*", vbDirectory)
'開始收集子目錄名稱
k = 0
Do While fA <> ""
If fA <> "." And fA <> ".." Then
If (GetAttr(mPath & "\" & fA) And vbDirectory) = vbDirectory Then
k = k + 1
mAry(k) = fA
End If
End If
fA = DirLoop
'--------------遍歷各子目錄--------
Application.DisplayAlerts = False
For i = 1 To k
fA = Dir(mPath & "\" & mAry(i) & "*.xls*")
Do While fA <> ""
If fA <> ThisWorkbook.Name Then
Set wb = Workbooks.Open(mPath & "\" & mAry(i) & "\" & fA, , False) '打開
wb.Save '保存
wb.Close True '關閉
End If
fA = Dir
Loop
Next i
Application.DisplayAlerts = True
MsgBox "處理完成!"
End Sub
哎,沒想到還是自己解決了,查了下dir就搞定了