附加的是一个可能的解决方案,作为一个vbs,可以从vba
可用的运行
感谢Sid Rout对他的建议编辑 RecursiveFile(objWB)
警告:有太多同时打开的书籍(在vbs
递归地狱期间我达到512 )可能会导致内存问题 - 在这种情况下,应该依次更新每个主要分支,然后在继续下一个分支之前关闭这些工作簿.
它能做什么
strFilePath
Arr
strFilePath
关闭而不保存strFilePath
然后保存并关闭编辑:更新代码以修复vbs递归问题
Public objExcel, objWB2, lngCnt, Arr()
Dim strFilePath, vLinks
`credit to Sid Rout for updating `RecursiveFileRecursiveFile(objWB)`
Erase Arr
lngCnt = 0
Set objExcel = CreateObject("Excel.Application")
strFilePath = "C:\temp\main.xlsx"
With objExcel
.DisplayAlerts = False
.ScreenUpdating = False
.EnableEvents = False
End With
Set objWB = objExcel.Workbooks.Open(strFilePath, False)
Call RecursiveFile(objWB)
For Each vArr In Arr
objExcel.Workbooks(vArr).Close False
Next
objWB.Save
objWB.Close
Set objWB2 = Nothing
With objExcel
.DisplayAlerts = True
.ScreenUpdating = True
.EnableEvents = True
.Quit
End With
Set objExcel = Nothing
MsgBox "Complete"
Sub RecursiveFile(objWB)
If Not IsEmpty(objWB.LinkSources()) Then
For Each vL In objWB.LinkSources()
ReDim Preserve Arr(lngCnt)
'MsgBox "Processing File " & vL
Set objWB2 = objExcel.Workbooks.Open(vL, False)
Arr(lngCnt) = objWB2.Name
lngCnt = lngCnt + 1
RecursiveFile objWB2
Next
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
工作ScreenShots