+ Reply to Thread
Results 1 to 10 of 10

Undoing a macro

  1. #1
    MissyLovesExcel
    Guest

    Undoing a macro

    Once a macro is run, can you "undo" it? Or, is there a second macro that will
    reverse any previous macro just run?

  2. #2
    Niek Otten
    Guest

    Re: Undoing a macro

    No, You'll have to take care of that yourself

    --
    Kind regards,

    Niek Otten

    "MissyLovesExcel" <[email protected]> wrote in
    message news:[email protected]...
    > Once a macro is run, can you "undo" it? Or, is there a second macro that
    > will
    > reverse any previous macro just run?




  3. #3
    Norman Jones
    Guest

    Re: Undoing a macro

    Hi Missy,

    See John Walkenbach's Undo notes at:

    http://www.j-walk.com/ss/excel/tips/tip23.htm

    ---
    Regards,
    Norman



    "MissyLovesExcel" <[email protected]> wrote in
    message news:[email protected]...
    > Once a macro is run, can you "undo" it? Or, is there a second macro that
    > will
    > reverse any previous macro just run?




  4. #4
    Jim Thomlinson
    Guest

    RE: Undoing a macro

    Nope. There is no Back button. Run is run and deleted is gone. You could
    write something to reverse some actions but some actions are permanent. Be
    very careful what you write and prompt for any action that can not be undone.
    The undo button is also unavailable after the macro is run. You can use
    application.undo while a macro is running to undo the last action the last
    action performed.
    --
    HTH...

    Jim Thomlinson


    "MissyLovesExcel" wrote:

    > Once a macro is run, can you "undo" it? Or, is there a second macro that will
    > reverse any previous macro just run?


  5. #5
    GregR
    Guest

    Re: Undoing a macro

    Missy, you can't undo a macro, but you can revert the file to the state
    it was before the macro was run with this code:
    Sub RevertFile()

    wkname = ActiveWorkbook.path & "\" & ActiveWorkbook.Name
    ActiveWorkbook.Close Savechanges:=False

    Workbooks.Open FileName:=wkname

    End Sub

    HTH

    Greg


  6. #6
    Ed
    Guest

    Re: Undoing a macro

    That would seem to fall apart if the macro contained a Save command. And
    really it's no different than saving the file just before you run your
    macro, then closing without saving changes if you don't like the results.

    "GregR" <[email protected]> wrote in message
    news:[email protected]...
    > Missy, you can't undo a macro, but you can revert the file to the state
    > it was before the macro was run with this code:
    > Sub RevertFile()
    >
    > wkname = ActiveWorkbook.path & "\" & ActiveWorkbook.Name
    > ActiveWorkbook.Close Savechanges:=False
    >
    > Workbooks.Open FileName:=wkname
    >
    > End Sub
    >
    > HTH
    >
    > Greg
    >




  7. #7
    GregR
    Guest

    Re: Undoing a macro

    Ed, you are absolutely right, but if it doesn't contain a save command,
    it is an alternative to recover the file.

    Greg


  8. #8
    Harald Staff
    Guest

    Re: Undoing a macro

    Hi Greg

    You are assuming that the macro is simply doing things to 'the' file. A
    single macro can delete gigs of files from a hard drive, mess up the
    registry, refurnish the desktop, corrupt a few databases, email lots of
    nigerian spam, you name it. The undo buffer would have to be infinite, so no
    one could afford to create it.

    Best wishes Harald

    "GregR" <[email protected]> skrev i melding
    news:[email protected]...
    > Ed, you are absolutely right, but if it doesn't contain a save command,
    > it is an alternative to recover the file.
    >
    > Greg
    >




  9. #9
    GregR
    Guest

    Re: Undoing a macro

    Harald, I absolutely agree, and if any of the concerns expressed by
    Harald or Ed pertain to your situation my solution will not work. I am
    just trying to express a solution to a simple macro that only acts on
    the active file and does not contain a save command. HTH

    Greg


  10. #10
    Registered User
    Join Date
    06-05-2019
    Location
    Hong Kong
    MS-Off Ver
    2003
    Posts
    1

    Re: Undoing a macro

    Quote Originally Posted by GregR View Post
    Missy, you can't undo a macro, but you can revert the file to the state
    it was before the macro was run with this code:
    Sub RevertFile()

    wkname = ActiveWorkbook.path & "\" & ActiveWorkbook.Name
    ActiveWorkbook.Close Savechanges:=False

    Workbooks.Open FileName:=wkname

    End Sub

    HTH

    Greg
    I registered for this forum - just to be able to say a big Thank You to GregR.
    Although others have critiqued the VBA code by saying that it only works if you had not saved the Excel file after you executed the macro (that you now want to undo). I thought that was obvious to seasoned PC users.
    It does not detract from the usefulness of GregR's contribution.
    I used his VBA code, saved it, assigned it to a custom button on the Excel toolbar and pasted an icon picture of a reversing rounded arrow.
    It works very well.
    I was looking for a way to Undo a macro used to sort an Excel range.
    This is it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1