用For For循环遍历所有的工作表VBA

为什么这个macros不会改变我所有工作表的颜色?
它只适用于我的活动工作簿的第一个工作表。
我希望它能通过我工作簿的所有工作表。 感谢名单

Option Explicit Private Sub CheckBox13_Click() Dim I As Long, j As Long Dim ws As Worksheet For Each ws In ActiveWorkbook.Worksheets If CheckBox13.Value = True Then For I = 1 To 700 For j = 1 To 10 If Cells(I, j).Interior.Color = RGB(252, 252, 250) Then Cells(I, j).Interior.Color = RGB(217, 217, 217) End If Next j Next I End If If CheckBox13.Value = False Then For I = 1 To 700 For j = 1 To 10 If Cells(I, j).Interior.Color = RGB(217, 217, 217) Then Cells(I, j).Interior.Color = RGB(252, 252, 250) End If Next j Next I End If Next End Sub 

当您使用引用活动工作表的Cells(I, j) 。 你会想在你的引用中使用ws对象,如下所示:

 ws.Cells(I, j)