How are you invoking the undo? If your using the escape key or control + z, you could try capturing the keystrokes and run your code from there.
Code:
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
'set form keyPreview to yes
If KeyCode = vbKeyEscape Then
'run your code
ElseIf KeyCode = vbKeyControl And Shift = 2 Then
'run your code
End If
End Sub
You can also do it by specific controls instead of form. You'll need to experiment.
If this helped, please click the star * at the bottom left and add to my reputation- Thanks