Sub AddBar()
Dim comBar As CommandBar
'Delete the commandbar if it already exists
On Error Resume Next
Application.CommandBars("MyBar").Delete
On Error GoTo 0
'Create a floating commandbar with an Undo button on it
Set comBar = Application.CommandBars.Add("MyBar", msoBarFloating)
comBar.Controls.Add ID:=128 '128 is the ID of the Undo button
comBar.Visible = True
End Sub
DK
The command button idea is the one I like for this app. however after testing it I have found 1 problem with it.
The sheets it will be on are part protected and if the user presses the button and there is nothing to undo then it just breaks the code.
Any ideas of how toget round this?
Dan.
Private Sub CommandButton1_Click()
Err.Clear
On Error Resume Next
Application.Undo
If Err.Number<> 0 Then MsgBox "Cannot undo"
End Sub
Private Sub CommandButton1_Click()
On Error Resume Next
Application.Undo
End Sub
Sub Macro1()
'A very simple demonstration of Application.OnUndo
Range("A1:A10").Formula = "=rand()"
Application.OnUndo "Undo Macro1", "UndoMacro1"
End Sub
Sub UndoMacro1()
Range("A1:A10").ClearContents
End Sub