我正在尝试使用Excel 2013了解VBA中的Application.OnUndo和Application.OnRepeat。我尝试使用以下描述的方法: http://msdn.microsoft.com/en-us/library/office/ff194135(v=office.15).aspx
我的撤消命令有效,但随后禁用了重复命令(工具栏中显示为灰色)。我做错了什么?
我的代码:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Cells(1, 1).Value = ActiveSheet.Cells(1, 1).Value + 1
Application.OnRepeat "Repeat", "Repeat1"
Application.OnUndo "Undo", "Undo1"
End Sub
在一个模块中:
Sub Undo1()
ActiveSheet.Cells(1, 1).Value = ActiveSheet.Cells(1, 1).Value - 1
End Sub
Sub Repeat1()
ActiveSheet.Cells(1, 1).Value = ActiveSheet.Cells(1, 1).Value + 1
End Sub
我也试过这个:
Sub Undo1()
ActiveSheet.Cells(1, 1).Value = ActiveSheet.Cells(1, 1).Value - 1
Application.OnRepeat "Repeat", "Repeat1"
End Sub
Sub Repeat1()
ActiveSheet.Cells(1, 1).Value = ActiveSheet.Cells(1, 1).Value + 1
Application.OnUndo "Undo", "Undo1"
End Sub