Set wbCur = ActiveWorkbook
Set objExcel = CreateObject("Excel.application") For i = 1 To nbDay today = Range("contribStart").Offset((i - 1) * nbCFPerDay + 1, 0) year = Application.WorksheetFunction.Text(today, "yyyy") monthAndDay = Application.WorksheetFunction.Text(today, "MMMdd") Application.DisplayAlerts = False 'Application.Visible = True Application.ScreenUpdating = False Set targetWb = objExcel.Workbooks.Open(targetPath & "\" & year & "\" & monthAndDay _ & "\" & targetSheet, ReadOnly:=True) For j = 1 To nbCFPerDay wbCur.Sheets("Contrib").Range("ContribStart").Offset((i - 1) * nbCFPerDay + j, 4) _ = targetWb.Sheets(targetTab).Range(CFPos(j)) wbCur.Sheets("Contrib").Range("ContribStart").Offset((i - 1) * nbCFPerDay + j, 5) _ = targetWb.Sheets(targetTab).Range(CFLimitPos(j)) Next j targetWb.Close Next i
一个实际中要到的例子,保存一下。