我有一个包含许多文件的文件夹,我需要从中:打开本周的文件,将它们存储在一个数组中,将它们传递给一个子,然后循环它们以获取摘要信息。
我可以从下面的代码中获取所需的日期文件。但是代码在将其存储在数组中并将其传递给数组时会引发错误。
Sub BatchProcessing()
firstday = Date - Weekday(Date) + 2 'To get the 1st day of week
lastday = Date - Weekday(Date) + 6 'To get the 5th day of week
MyPath = "P:\Data\" 'Path where my files were present
Dim Day
Dim strArray(0 To 5) As String
iCount=0
For Day = firstday To lastday 'To loop through all 5 day files
formatted_date = Format(Day, "yyyyMd")
MyTemplate = "TestFile" & formatted_date & ".xlsx" ' Set the template.
Workbooks.Open MyPath & MyTemplate
strArray(iCount) = ActiveWorkbook.Name
iCount = iCount+1
Next
CreateStats(strArray) 'Calling a sub which will do the required calculation
End Sub
Sub CreateStats(strArray As String)
For Each element in strArray
set OriginalWorkbook = strArray(i)
'Do the processing'
Next
End Sub