Consulting

Results 1 to 7 of 7

Thread: Undo option

  1. #1
    VBAX Contributor
    Joined
    May 2008
    Posts
    109
    Location

    Undo option

    Hi All,
    is it possible to add some lines of code whatever macro the way it can also work as a sort of UNDO option and allow me to reverse back at the time just before I have launch it?

    Thanks in advance

    sasa

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Code wipes the UNDO stack, so you would somehow save all the changes yourself, them re-apply. Not trivial.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Contributor
    Joined
    May 2008
    Posts
    109
    Location
    I see. But I think this way is very expensive, a lot of saved data....
    Thank you again

    sasa

  4. #4
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,075
    Location
    Normally when you execute a macro its because the User believes that certain conditions have been met or that it is triggered by particular condition/s on the sheet.

    However if you are unsure, that the conditions are right, yet you still feel you need to execute a macro... then you might try saving the file first. This way if the macro does something that then proves unsuitable, close the active book without saving changes.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  5. #5
    VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,005
    Location
    You have 2 options here:
    1. Create a worksheet and macro to track changes made to the workbook you will then be able to create a macro to reverse these changes
    2. Create a macro that reverses the effect of the one you ran and call it MyUnDoMacro, then at the bottom of your original macro add this line
    [VBA] Application.OnUndo "Undo My Macro", "MyUnDoMacro"[/VBA]the Undo My Macro is what the user would see and the latter part calls the macro, now after your macro has run you just click on the undo as you would normally and hey presto macro reversed!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  6. #6
    VBAX Contributor
    Joined
    May 2008
    Posts
    109
    Location
    It is not possible copy the sheet of interest, make the changes, and then delete the copied sheet when one is sure of the changes or restore it if it is not so, maybe with a click on a icon on toolbar ?

    sasa

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Yes that would work if the changes are all about a single sheet. You could copy it, hide it, and just copy it back if required.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •