CTRL Z PARA EXCEL VBA

PABLOMOREIRAGV 11/06/2015 15:16:20
#447628
Olá pessoal,

Como já é de conhecimento de todos, no Excel não funciona o comando [Ô]Ctrl + Z[Ô] para desfazer/refazer uma ação após rodar uma macro. Queria saber se alguém conhece algum código que faça com que esta ação funcione e consiga desfazer a ação de um código executado.
Desde já agradeço.

Obrigado

Pablo Moreira
TUNUSAT 12/06/2015 11:11:17
#447657
PABLOMOREIRAGV,

Achei uns negócios bacaninhas, a saber:

=====================================================
Undoing a VBA Subroutine
http://www.j-walk.com/ss/excel/tips/tip23.htm
The Undo example
[ô]Custom data type for undoing
Type SaveRange
Val As Variant
Addr As String
End Type

[ô] Stores info about current selection
Public OldWorkbook As Workbook
Public OldSheet As Worksheet
Public OldSelection() As SaveRange


Sub ZeroRange()
[ô] Inserts zero into all selected cells

[ô] Abort if a range isn[ô]t selected
If TypeName(Selection) <> [Ô]Range[Ô] Then Exit Sub

[ô] The next block of statements
[ô] Save the current values for undoing
ReDim OldSelection(Selection.Count)
Set OldWorkbook = ActiveWorkbook
Set OldSheet = ActiveSheet
i = 0
For Each cell In Selection
i = i + 1
OldSelection(i).Addr = cell.Address
OldSelection(i).Val = cell.Formula
Next cell

[ô] Insert 0 into current selection
Application.ScreenUpdating = False
Selection.Value = 0

[ô] Specify the Undo Sub
Application.OnUndo [Ô]Undo the ZeroRange macro[Ô], [Ô]UndoZero[Ô]
End Sub


Sub UndoZero()
[ô] Undoes the effect of the ZeroRange sub

[ô] Tell user if a problem occurs
On Error GoTo Problem

Application.ScreenUpdating = False

[ô] Make sure the correct workbook and sheet are active
OldWorkbook.Activate
OldSheet.Activate

[ô] Restore the saved information
For i = 1 To UBound(OldSelection)
Range(OldSelection(i).Addr).Formula = OldSelection(i).Val
Next i
Exit Sub

[ô] Error handler
Problem:
MsgBox [Ô]Can[ô]t undo[Ô]
End Sub

=====================================================
Creating An Undo Handler To Undo Changes Done By Excel VBA
----- Class modules (1)
http://www.jkp-ads.com/Articles/UndoWithVBA01.asp
----- Class modules (2)
http://www.jkp-ads.com/Articles/UndoWithVBA02.asp
----- Implementation
http://www.jkp-ads.com/Articles/UndoWithVBA03.asp
----- Conclusion
http://www.jkp-ads.com/Articles/UndoWithVBA04.asp
=====================================================

Veja se funciona... depois posta um exemplo aqui no VBMania.

[][ô]s,
Tunusat.
Faça seu login para responder