test that there is something to undo before executing application.

P

pwrob

hi, is there a way to test that there is something to undo before executing
an Application.Undo?

Thanks,
pwrob
 
D

Dave Peterson

This works ok in xl2003 in my USA/English version:

If Application.CommandBars("Standard").Controls("Undo").Enabled = True Then
MsgBox "there's something to undo"
Else
MsgBox "nothing to undo"
End If
 
P

Peter T

On Error Resume Next
ud = Application.CommandBars.FindControl(ID:=128).ListCount
' could test for err.number, if 0 but ud=0
' probably means Redo has at least 1 item that'll
' get called with app.undo
On Error GoTo 0

Even though Commandbars are replaced with the Ribbon in 2007 this still
appears to work in 2007

If the intention is to call .Undo but you're only concerned about an error
if Undo is empty, just do simply

On error resume next
Application.Undo
On error goto 0

Regards,
Peter T
 
P

pwrob

thank you for the prompt reply.

i know the app undo throws error 1004 if there is nothing to undo and i'm a
bit concerned that something else might throw the same error...

do you know whether i can place the on error resume next statement in the
middle of my sub? if so, will it apply to all code thereafter or from the
beginning of the sub?

thanks,
pwrob
 
P

pwrob

hi again, just realized that ...goto 0 disables the error handling - this
will work! thanks again - cheers, pwrob
 
Top