+ Reply to Thread
Results 1 to 8 of 8

macro to undo user changes since last save

  1. #1
    Registered User
    Join Date
    12-15-2010
    Location
    Minneapolis
    MS-Off Ver
    Excel 2003
    Posts
    3

    macro to undo user changes since last save

    Hi I would like a macro to undo all user changes since the last time it was saved.
    Basically, I have a worksheet that requires users to enable macros before they use it because it can still be used without enabling macros and can give incorrect results if done so.

    All sheets are hidden and unhidden when user enables macros and clicks button.

    On close, if worksheet is detected to have been saved already. then macro will rehide all sheets except for 1, saves itself, and closes.

    If worksheet has not been saved, a form shows up asking if user wants to save.
    Click yes, then the macro hides all sheets except for 1, saves itself, and closes.

    Click no is where I have a problem.

    In the case where the user has inputted data already, clicked save, and inputted more data - I want the no button to undo all changes leading up to the last save, rehide all sheets except for 1, save itself, and close.

    Is this possible? Any help would be appreciated, thanks!
    Last edited by nguye569; 12-15-2010 at 11:59 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: macro to undo user changes since last save

    How can they use the workbook if all sheets are hidden until macros are enabled?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: macro to undo user changes since last save

    Hi nguye569,

    Would a close of the workbook without saving changes since it was last saved work?

    There is a VBA call to do just that. Read: http://support.microsoft.com/kb/213428
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    12-15-2010
    Location
    Minneapolis
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: macro to undo user changes since last save

    @royUK - the first sheet is visible and there is a button to unlock all the hidden sheets. That button can be clicked once macros are enabled.

    @MarvinP - I have seen that already. It helped me a little bit, but there is a loophole.
    If the user has unlocked sheets to edit data and the user clicks save in the middle of working and adds more data. If the person chooses to not save the most recent information, and I supress the save changes dialog box then the next time the sheet is open, the sheets will be all visible again. However, I need the sheet to always rehide all the sheets except for sheet 1 whether the use decides to save changes or not save changes.

    so the steps would do this.
    1. click No when asked to save changes
    2. Undo all user changes since last save
    3. make sheet 1 visible
    4. hide all other sheets
    5. Save
    6. close

    Step 2 is what I can't find the code to do

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: macro to undo user changes since last save

    Basically, I have a worksheet that requires users to enable macros before they use it because it can still be used without enabling macros and can give incorrect results if done so.
    Your reply to my question doesn't make sense

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: macro to undo user changes since last save

    To Undo all users changes from last time it was saved:

    Why can't you simply open it up again without saving any changes?

  7. #7
    Registered User
    Join Date
    12-15-2010
    Location
    Minneapolis
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: macro to undo user changes since last save

    Quote Originally Posted by MarvinP View Post
    To Undo all users changes from last time it was saved:

    Why can't you simply open it up again without saving any changes?
    I have a beforeclose event that hides all worksheets except for sheet 1 when the workbook is closed. Sheet 1 has only a button on it to unhide all the worksheets (I did this to prevent the user from using the workbook unless macros are enabled).

    Because of the beforeclose event, there will be a prompt to ask the user if they want to save the changes. If the user clicks yes then there are no problems.

    If the user clicks no, and they saved their work sometime after opening the file initially, then the next time they open the file all worksheets are still visible (something I don't want to happen).

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: macro to undo user changes since last save

    In the Before_Close event you should run the code to hide the sheets, then save the workbook. If the user has saved the workbook previously you can't undo anything before that

+ 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