0
我第一次嘗試創建Excel VBA。如何將參數傳遞給VBA中的撤消處理程序
下面的宏本質上改變了細胞範圍內部的背景。
GenerateMarkerOnSheet將內部設置爲黑色。 ResetMarkerOnSheet旨在回滾撤消上的更改。
是否有可能通過 Application.OnUndo?將前一個內部作爲參數傳遞給撤消手柄(ResetMarkerOnSheet)?
如果是這樣,我應該怎麼做呢?
Sub GenerateMarkerOnSheet()
'
' GenerateMarkerOnSheet Macro
' Macro recorded 29/01/2010 by Everyone
'
'
StartIndex = 99
RangeGap = 100
StartCell = "A"
EndCell = "BU"
PreviousBackground = 1
Do While StartIndex < 65536
For Each c In Worksheets(ActiveSheet.Name).Range(StartCell & StartIndex & ":" & EndCell & StartIndex)
If PreviousBackground = 1 Then
PreviousBackground = c.Interior.ColorIndex
End If
c.Interior.Color = RGB(0, 0, 0)
Next
StartIndex = StartIndex + RangeGap
Loop
' How to pass PreviousBackground to the call below
Application.OnUndo "Undoing", "ResetMarkerOnSheet"
End Sub
Sub ResetMarkerOnSheet()
'
' ResetMarkerOnSheet Macro
' Macro recorded 29/01/2010 by Everyone
'
'
StartIndex = 99
RangeGap = 100
StartCell = "A"
EndCell = "BU"
Do While StartIndex < 65536
For Each c In Worksheets(ActiveSheet.Name).Range(StartCell & StartIndex & ":" & EndCell & StartIndex)
c.Interior.ColorIndex = PreviousBackground
Next
StartIndex = StartIndex + RangeGap
Loop
End Sub
謝謝,但可以從'Application.OnUndo'提供撤銷處理程序。 雖然有好主意,但要使用隱藏的工作表。 我會給它一個鏡頭! – Everyone 2010-02-03 12:00:51