+ Reply to Thread
Results 1 to 7 of 7

Application.EnableEvents causing undo/redo problem

  1. #1
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Application.EnableEvents causing undo/redo problem

    Hi

    In the attached workbook when I run the "Disable Macro" the Events (currenty selection change is used) fails but undo redo work fine i.e if I type something and then undo ,it successfully undoes.

    Now If I run "Enable" macro then the events do fire but now the undo and redo don't work

    How can I get both the functionalities at a time?

    Help would be greatly rather GREATLY appreciated

    Best Regards
    Imran Bhatti
    Attached Files Attached Files
    Teach me Excel VBA

  2. #2
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Application.EnableEvents causing undo/redo problem

    To clarify, you say that with "Disable Macro" undo/redo work fine if you MANUALLY type and then undo/redo correct?

    When you have it set to "Enable" are you also MANUALLY entering something and trying to undo/redo or do you mean having it undo/redo something the macro did?

    I ask as undo/redo just plain doesnt work for something a macro does. If you have a macro enter content in a cell for example, undo is greyed out. If you manually entered the same thing it would be possible to undo.

    If however you manually entered the content in both cases it would take some digging to see why it has been impacted.
    Ways to get help: Post clear questions, explain your overall goal, supply as much background as possible, respond to questions asked of you by those trying to help and post sample(s) files.

    "I am here to help, not do it for people" -Me

  3. #3
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Application.EnableEvents causing undo/redo problem

    Thanks ZeroCool for the reveiw

    Yes I am doing changes manually. I mean if I type something in the sheet with typing,change the font size of any cell manually, or I accidentally delete something manually and I immediatedly reliazed it was not to delete then I should be able to undo/redo that manual change with the default buttons of undo/redo.

    Hope It makes sense.

    Best Regards
    Imran Bhatti

  4. #4
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Application.EnableEvents causing undo/redo problem

    Yes that clarifies. So in both cases we are talking about manual changes being undone or redone. That is odd that undo/redo would be affected then.

    Ill check out the file see what we can find

  5. #5
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Application.EnableEvents causing undo/redo problem

    O yea that makes sense now.

    So lets talk about what is happening here in relation to what we discussed about macros not allowing undo/redo.

    When you disable events and then type something into a cell, as soon as you are done typing what do you do? hit enter or tab right? That effectively changes the active cell right? Well you disabled events so your macro doesnt fire off in this case and the last thing you did was a manual entry.

    When you have events enabled and then type something into a cell, as soon as you hit enter or tab you are executing your macro because events are now enabled, meaning the very last thing you did after making that entry was run a macro, hence Excel cannot undo/redo as the last thing you actually did was run a macro, not make a manual entry

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Application.EnableEvents causing undo/redo problem

    How can I get both the functionalities at a time?
    I usually try to be optimistic, but I don't think you'll be able to retain both event code and the undo stack. Everytime a VBA macro is called (and a selectionchange macro is going to get called frequently -- everytime you move the cursor around the spreadsheet), the undo stack is cleared, and there is nothing (that I am aware of) to change that behavior of Excel. A choice to use event procedures (especially frequently called events like selectionchange) is a choice to not have a reliable undo stack, and the choice to have a reliable undo stack is a choice not to use event procedures. You as the programmer need to choose which is more important -- the event procedure or the undo stack.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  7. #7
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Application.EnableEvents causing undo/redo problem

    Thanks ZeroCool and Mshortly for reviewing the problem

    I found something that is near to what I am after.
    http://www.jkp-ads.com/Articles/UndoWithVBA00.asp
    How can we adopt it for my WB? I have attached the readymade sample available at the above link.

    Best Regards
    Imran Bhatti
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Undo Redo Grayed out
    By markDuffy in forum Excel General
    Replies: 4
    Last Post: 07-05-2020, 03:30 AM
  2. [SOLVED] Application.EnableEvents and Undo
    By Brandon2013 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-25-2017, 02:58 PM
  3. [SOLVED] Need Undo/Redo on QAT
    By KiwiRickToo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-05-2016, 05:19 PM
  4. Undo Redo Disabled
    By frank35 in forum Excel General
    Replies: 3
    Last Post: 11-15-2013, 06:04 PM
  5. redo / undo action
    By aer10 in forum Excel General
    Replies: 3
    Last Post: 08-12-2013, 09:14 AM
  6. Application.EnableEvents Worksheet_Change problem
    By bmihealthcare in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-27-2012, 12:05 PM
  7. simple undo/redo vba
    By randell.graybill in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-28-2009, 10:10 PM

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