Solved

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

Posted on 2013-05-28
11
2,631 Views
Last Modified: 2013-05-30
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.
0
Comment
Question by:Matt Johnson
  • 6
  • 5
11 Comments
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 39201631
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.
0
 
LVL 13

Expert Comment

by:Alexander Eßer [Alex140181]
ID: 39201651
You can start here (for enabling/disabling hot keys and toolbars), maybe it helps:

http://www.rondebruin.nl/win/s4/win011.htm

http://www.rondebruin.nl/win/s5/win005.htm

http://www.rondebruin.nl/win/section6.htm
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 39201654
you can adjust the number of undo available
Please read as...
you can adjust the number of undo levels available
:)
0
 
LVL 13

Expert Comment

by:Alexander Eßer [Alex140181]
ID: 39201661
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
0
 
LVL 13

Accepted Solution

by:
Alexander Eßer [Alex140181] earned 500 total points
ID: 39201679
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 39201684
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.
0
 
LVL 13

Expert Comment

by:Alexander Eßer [Alex140181]
ID: 39201985
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 ;-)
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 39202275
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.
0
 
LVL 13

Expert Comment

by:Alexander Eßer [Alex140181]
ID: 39202432
You're new here.

So what?!
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 39202618
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)

[ http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_20753813.html ]

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

[ http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_21598125.html#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.
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 39208273
You're welcome,  mattej1.

(Sigh)
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This is about my first experience with programming Arduino.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now