嗨,我一直在分配给同一工作簿中多张工作表上的表单按钮的宏中使用以下代码
Sub RunAll()
Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
wks.Select
Application.ScreenUpdating = False
Call UnprotectAll
Call BasicLoop
Call ProtectAll
Next wks
Application.ScreenUpdating = True
End Sub
这是它调用的宏
Sub UnprotectAll()
Dim sh As Worksheet
Dim yourPassword As String
yourPassword = ""
For Each sh In ActiveWorkbook.Worksheets
sh.Unprotect Password:=yourPassword
Next sh
End Sub
Sub BasicLoop()
For x = 5 To 32
If Cells(x, 9) <> red Then
Cells(x, 10) = "Basic"
Else: Cells(x, 10) = ""
End If
Next x
End Sub
Sub ProtectAll()
Dim sh As Worksheet
Dim yourPassword As String
yourPassword = ""
For Each sh In ActiveWorkbook.Worksheets
sh.Protect Password:=yourPassword
Next sh
End Sub
我要更改的是单击表单按钮时仅更新活动工作表,而不是工作簿中的所有工作表?我仍在学习,所以一个简单的解决方案将是最好的欢呼!