Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can I support Undo?

82 views
Skip to first unread message

Matthew Connor

unread,
Jun 23, 2003, 6:01:39 PM6/23/03
to
Is there a relatively easy way to provide the user with a means of
'undoing' a macro?

I have a button that does x,y and z to the worksheet. User clicks the
button, decides it was a mistake and wants to 'undo'.

It could be so easy -
Application.SaveUndoPoint("Execute Macro: MyMacro")

at the end of the macro.


Waiting to be disappointed,

Matthew

Vasant Nanavati

unread,
Jun 23, 2003, 7:35:14 PM6/23/03
to
Hi Matthew:

Hopefully you didn't wait too long. No, there is no easy way to do this. You
would have to write your own custom routine, which would involve
"remembering" the state of the relevant parts of the workbook.

Regards,

Vasant.

"Matthew Connor" <mco__DONTNEEDTHIS__nnor1600@YA__DONTNEEDTHIS__HOO.com>
wrote in message news:10564057...@nntp.acecape.com...

Matthew Connor

unread,
Jun 23, 2003, 7:44:10 PM6/23/03
to
Vasant Nanavati wrote:
> Hi Matthew:
>
> Hopefully you didn't wait too long. No, there is no easy way to do this. You
> would have to write your own custom routine, which would involve
> "remembering" the state of the relevant parts of the workbook.
>
> Regards,
>
> Vasant.
>
I was afraid it might come to that. That's why I stuck in 'relatively
easy' - 'cause backwards-writing code makes my head hurt.

Thanks,

Matthew


>
>
> "Matthew Connor" <mco__DONTNEEDTHIS__nnor1600@YA__DONTNEEDTHIS__HOO.com>
> wrote in message news:10564057...@nntp.acecape.com...
>
>>Is there a relatively easy way to provide the user with a means of
>>'undoing' a macro?
>>

<snipped>

Henry

unread,
Jun 23, 2003, 7:50:50 PM6/23/03
to
Matthew,
As Vasant has said, there's no simple way, but here's a suggestion.

Before the macro does anything else, copy the 'live' worksheet to a
worksheet you name "Temp"
Run the rest of your macro on the 'live' sheet
If everything is OK the "temp" sheet will be overwritten the next time the
macro is run.
If there was an errror and you want to go back (Undo) what the macro has
done,
write another macro to copy "Temp" back to the 'live' worksheet.
Set this up on a button marked "Undo".

Another way is for your macro to work on the "temp" sheet and to copy it
over the 'live' sheet if
the user hits a button named "Save"

HTH
Henry


"Matthew Connor" <mco__DONTNEEDTHIS__nnor1600@YA__DONTNEEDTHIS__HOO.com>
wrote in message news:10564057...@nntp.acecape.com...

Dana DeLouis

unread,
Jun 23, 2003, 8:03:46 PM6/23/03
to
Matthew...Not too many people like this idea, so I'll just throw it out.
This shows just some of the capabilities of "Track Changes."
It is not the best solution I know, but there really is no way to "Undo" vba
changes. This might give you some ideas for your own situation.
Copy the following 3 macros to a workbook, and save it.
Hit Alt+F8, and run "Undo_Activate"
This will Share your workbook, and add some stuff to A1:A2.
Now, Hit Alt+F8 and run the "Make_Some_Changes_With_VBA" macro.
The macro makes a mess of the sheet.
Not, Hit Alt + F8 and run "Undo"
Your sheet should go back to the way it was.
You can get as fancy as you want with the "RejectChanges" options.
Again, this is just a demo version. You can get pretty fancy if you wish.

Note: Also remember that Excel's "AutoRecover" feature also wipes out the
undo history.

Sub Undo_Activate()
[A1] = "One"
[A2] = "Two"

Application.DisplayAlerts = False

ActiveWorkbook.SaveAs _
Filename:=ActiveWorkbook.FullName, _
AccessMode:=xlShared

With ActiveWorkbook
.HighlightChangesOptions When:=xlAllChanges
.ListChangesOnNewSheet = False
.HighlightChangesOnScreen = True
End With
End Sub

Sub Make_Some_Changes_With_VBA()
' = = = = = = = = = =
' Do some changes manually...
' = = = = = = = = = =
' VBA won't record the following, but this
' is just something to add...
' Shows 1 way to "Undo" VBA changes
' = = = = = = = = = =
[A1:D20] = "Lots of Changes"
[A:D].Columns.AutoFit
' ...and kill the undo button
ActiveWorkbook.Save
End Sub

Sub Undo()
'// Dana DeLouis
' Try to go back...

Application.DisplayAlerts = False
ActiveWorkbook.RejectAllChanges
ActiveWorkbook.ExclusiveAccess
End Sub


--
Dana DeLouis
Windows XP & Office XP
= = = = = = = = = = = = = = = = =


"Matthew Connor" <mco__DONTNEEDTHIS__nnor1600@YA__DONTNEEDTHIS__HOO.com>
wrote in message news:10564118...@nntp.acecape.com...

Matthew Connor

unread,
Jun 23, 2003, 8:05:32 PM6/23/03
to
Henry wrote:
> Matthew,
> As Vasant has said, there's no simple way, but here's a suggestion.
>
> Before the macro does anything else, copy the 'live' worksheet to a
> worksheet you name "Temp"
> Run the rest of your macro on the 'live' sheet
> If everything is OK the "temp" sheet will be overwritten the next time the
> macro is run.
> If there was an errror and you want to go back (Undo) what the macro has
> done,
> write another macro to copy "Temp" back to the 'live' worksheet.
> Set this up on a button marked "Undo".
>
> Another way is for your macro to work on the "temp" sheet and to copy it
> over the 'live' sheet if
> the user hits a button named "Save"
>
> HTH
> Henry
>
Thanks for the suggestion. I can definitely work with that methodology
in several places.

Matthew

>
> "Matthew Connor" <mco__DONTNEEDTHIS__nnor1600@YA__DONTNEEDTHIS__HOO.com>
> wrote in message news:10564057...@nntp.acecape.com...
>
>>Is there a relatively easy way to provide the user with a means of
>>'undoing' a macro?
>>

<snip>
>

Matthew Connor

unread,
Jun 23, 2003, 9:22:57 PM6/23/03
to
Dana DeLouis wrote:
> Matthew...Not too many people like this idea, so I'll just throw it out.
> This shows just some of the capabilities of "Track Changes."
> It is not the best solution I know, but there really is no way to "Undo" vba
> changes. This might give you some ideas for your own situation.
> Copy the following 3 macros to a workbook, and save it.
> Hit Alt+F8, and run "Undo_Activate"
> This will Share your workbook, and add some stuff to A1:A2.
> Now, Hit Alt+F8 and run the "Make_Some_Changes_With_VBA" macro.
> The macro makes a mess of the sheet.
> Not, Hit Alt + F8 and run "Undo"
> Your sheet should go back to the way it was.
> You can get as fancy as you want with the "RejectChanges" options.
> Again, this is just a demo version. You can get pretty fancy if you wish.
>
> Note: Also remember that Excel's "AutoRecover" feature also wipes out the
> undo history.
>
<code snipped>

Thanks Dana. It does come closest to setting pure Undo save-points.

Being a moody-loner, I'm not a user of Track Changes -- I doubt this
idea would have occurred to me. It certainly is a cool idea. My users
are not very sophisticated (don't use Track Changes)- the changes
apparent in the application from the Shared/Track Changes would just
cause too much confusion. I don't think I want to open up that can of
worms.

I could imagine using this for something only I (or a few
well-informed users) was going to be using.

Thanks,

Matthew

Steve Muller

unread,
Jun 24, 2003, 8:26:36 PM6/24/03
to
I had a button in the locked title area that the user
could click on to delete the row the active cell was in.
I wanted an undo button (restore the deleted row). Found
that the only way to allow an undo was to do the original
delete with "Sendkeys". If your "do-ing" macro isn't too
complicated, this might work.

Examples below: UndoDeleteRow would not work if Macro1
was previously used, however, it would work if DeleteRow
was previously used.

Sub Macro1()
Selection.EntireRow.Delete
End Sub

Sub DeleteRow()
SendKeys ("%EDR~")
End Sub

Sub UndoDeleteRow()
SendKeys ("%EU")
End Sub

Hope this helps.

0 new messages