Link to home
Start Free TrialLog in
Avatar of Matt Johnson
Matt Johnson

asked on

Excel 2010 - VBA code to disable undo command for a workbook

I am using excel 2010 and I need to find a way to disable the undo command when I open a certain workbook.  Everything I am able to find right now is for earlier versions of excel and I read somewhere and learned from my own attempts that I need a completely different approach for this in excel 2010.  I was thinking of disabling / enabling the command based on the workbook's activate / deactivate events.

Thanks for your help.
Avatar of [ fanpages ]
[ fanpages ]

Hi,

Are you able to update the Windows Registry within the run-time environment?

Although not stated explicitly within the following article, you can adjust the number of undo available within the Workbook_Open() event code, & restore within the Workbook_BeforeClose() event code, or the Activate/Deactive events as you suggested:

"How to modify the number of undo levels in Excel"
[ http://support.microsoft.com/?kbid=211922 ]

Simply use the "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Excel\Options" key for Microsoft Excel 2010.

---
By default, Excel allocates RAM for 16 undo levels. The registry setting that is described in this article lets you change the default value to a value that you specify.

If the undo history is set to zero, no memory is allocated for undoing actions. The higher the undo history value, the more memory Excel allocates for the history. This directly affects the performance of your computer when you run Excel.

Note When you run a Visual Basic for Applications macro, Excel allocates no memory for undoing actions. This feature is disabled for optimization of performance when you run a macro.

To use Registry Editor to change the number of undo levels, follow these steps.

Important This section, method, or task contains steps that tell you how to modify the registry. However, serious problems might occur if you modify the registry incorrectly. Therefore, make sure that you follow these steps carefully. For added protection, back up the registry before you modify it. Then, you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click the following article number to view the article in the Microsoft Knowledge Base:
322756 How to back up and restore the registry in Windows

    Close any programs that are running.
    Click Start, click Run, type regedit in the Open box, and then click OK.
    In Registry Editor, expand one of the following registry subkeys, as appropriate for the version of Excel that you are running:

    Microsoft Office Excel 2007
    HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Options
    Microsoft Office Excel 2003
    HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Excel\Options
    Microsoft Excel 2002
    HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Excel\Options
    Microsoft Excel 2000
    HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\Excel\Options
    On the Edit menu, point to New, and then click DWORD Value. Select New Value #1, type UndoHistory, and then press ENTER.
    On the Edit menu, click Modify.
    In the Edit DWORD Value dialog box, click Decimal under Base. Type a value between 0 and 100 in the Value box, click OK, and then exit Registry Editor.
    Start Excel. Excel stores an undo history for the number of actions that you specified in step 6.
---

BFN,

fp.
you can adjust the number of undo available
Please read as...
you can adjust the number of undo levels available
:)
By the way: IT'S A VERY VERY BAD IDEA TO TOUCH THE REGISTRY IN ORDER TO GET THINGS DONE ;-)
It's just a messy workaround :-( = (very) bad paractice
ASKER CERTIFIED SOLUTION
Avatar of Alex [***Alex140181***]
Alex [***Alex140181***]
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
By the way: IT'S A VERY VERY BAD IDEA TO TOUCH THE REGISTRY IN ORDER TO GET THINGS DONE ;-)
It's just a messy workaround :-( = (very) bad paractice

It is not "messy" at all.  It is the most efficient method of meeting your needs.

The configurable settings are there for the purpose of changing them to suit your environment's requirements.

If you are careful, & follow the advice/instructions provided by Microsoft, then there is minimal risk.
I have NEVER seen anyone writing efficient AND good code (in terms of SW design and SW patterns) at the same time through manipulating the registry...
Nevertheless, in the end it's up to mattej1 to choose the "right" solution which suites him best ;-)
I have NEVER seen anyone writing efficient AND good code (in terms of SW design and SW patterns) at the same time through manipulating the registry...

You're new here.
You're new here.

So what?!
So what?!
If you were not a new member, then you may have seen some of my previous contributions that use the registry settings for tasks that are far from easy (if not impossible) using coded solutions.

For example, "URGENT- Auto enabling the Macros" (October 2003)

[ https://www.experts-exchange.com/questions/20753813/URGENT-Auto-enabling-the-Macros.html ]

Also, "Importing Excel Spreadsheet into Access 20[0]3" (October 2005)

[ https://www.experts-exchange.com/questions/21598125/Importing-Excel-Spreadsheet-into-Access-203.html?anchorAnswerId=15160522#a15160522 ]

Registry settings are there to be used, otherwise why would they be there at all?

I am sorry you are not as familiar with their usage & their possibilities, but that does not make them inefficient or detrimental to good coding techniques.  They can co-exist, &/or complement such techniques.
You're welcome,  mattej1.

(Sigh)