我在一个不断运行的工作簿中运行宏。当我打开另一个工作簿时,宏会中断,并且它会超出范围。如何锁定特定工作表上的宏?宏代码是:
Sub startTimer()
On Error Resume Next
ActiveSheet.Unprotect Password:="***"
Application.OnTime Now + TimeValue("00:00:01"), "Increment_count", Schedule:=False
Application.OnTime Now + TimeValue("00:00:01"), "Increment_count"
End Sub
Sub Increment_count()
If ActiveCell.Column = 9 Then
ActiveCell.Value = ActiveCell + 1
startTimer
Else
MsgBox "Timer works only in I column", vbCritical, "Error"
End If
End Sub
Sub stopTimer()
On Error Resume Next
Application.OnTime Now + TimeValue("00:00:01"), "Increment_count", Schedule:=False
ActiveSheet.Protect Password:="***"
ActiveWorkbook.Save
End Sub
答案 0 :(得分:1)
这个答案是Shai Rado评论的延伸
<ScrollView>
<RelativeLayout>
<LinearLayout/>
<RecyclerView/>
</RelativeLayout>
</ScrollView>
和Activeworkbook
引用了当前关注的工作表。更好的方法是命名您感兴趣的工作表并按名称获取该工作表。
Activesheet
还要看这个问题:Declaring variable workbook / Worksheet vba
此参考可能也很有用 http://www.excel-easy.com/vba/workbook-worksheet-object.html