Private Sub CommandButton1_Click()
Dim t, i As Integer
Dim fd, fs As String
fd = "C:\我的資料夾\"
t = 0
For i = 1 To 3
fs = fd & "麻辣" & CStr(i) & "日.xls" '把路徑弄出來加上檔名
Workbooks(fs).Open '開啟該檔
.Sheets("小計").Select '選該檔的小計sheet
t = t + Workbooks(fs).Sheets("日報").Cells(1, 1).Value '累加該欄位的值
Workbooks(fs).Close SaveChanges:=False '關檔
Next
Workbooks("結算").sheets("1").cells(1,1)=t '把累加結果放到結算.xls去
End Sub
Private Sub CommandButton1_Click()
Dim t, i As Integer
Dim fd, fs As String
fd = "C:\Users\ice\Desktop\TEST\"
t = 0
For i = 1 To 3
fs = fd & "工作表" & CStr(i) & "日.xls" '把路徑弄出來加上檔名
With Workbooks(fs).Open '開啟該檔-----目前錯誤出在這一步,陣列索引超出範圍
.Sheets("小計").Select '選該檔的小計sheet
t = t + .Sheets("小計").Cells(1, 1).Value '累加該欄位的值
.Close SaveChanges:=False '關檔
End With
Next
Workbooks("工作表結算").Sheets("1").Cells(1, 1) = t '把累加結果放到結算.xls去
End Sub作者: iceandy6150 時間: 2012-2-22 23:52