Code to Undo and Redo

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Code to Undo and Redo

Post by ABabeNChrist »

I tried to record undo and redo using Excel 2007 with no such luck.
I'm trying to find these codes so that I can attch to a custom tool bar i'm designing

User avatar
HansV
Administrator
Posts: 78237
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Code to Undo and Redo

Post by HansV »

There is no point in using Undo and Redo from code - running VBA code clears the undo/redo stack. But Excel has built-in undo and redo buttons; they have ID 128 and 129, respectively. So you could use code like this:

Dim cbb As CommandBarControl
Set cbb = CommandBars("Test").Controls.Add(msoControlSplitDropdown, 128, , , True)
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Code to Undo and Redo

Post by ABabeNChrist »

Hi HansV
I tried 128 and 129 and recieved the same error
No. 5 Error.JPG
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78237
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Code to Undo and Redo

Post by HansV »

Obviously, the code I posted was just an example. You should replace CommandBars("Test") with a reference to the custom toolbar that you're creating.

But why do you need this at all? Undo and Redo are already available on the Standard toolbar in Excel 2003 and before, and on the Quick Access Toolbar in Excel 2007 and later.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Code to Undo and Redo

Post by ABabeNChrist »

Thank you HansV
I will make the changes you suggested.
I’m designing a single tool bar that will have all the needed and basic tools in a single location.
It makes it more user friendly for a beginner.
Here is how it looks so far.
Tool Bar.JPG
You do not have the required permissions to view the files attached to this post.

User avatar
rory
5StarLounger
Posts: 817
Joined: 24 Jan 2010, 15:56

Re: Code to Undo and Redo

Post by rory »

Why not just add the actual Undo and Redo galleries to your tab?
Regards,
Rory

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Code to Undo and Redo

Post by ABabeNChrist »

Hi rory
Are you referring to the Quick Access Toolbar?

User avatar
rory
5StarLounger
Posts: 817
Joined: 24 Jan 2010, 15:56

Re: Code to Undo and Redo

Post by rory »

No, to your tab. Since you are using XML anyway, you might as well.
Regards,
Rory

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Code to Undo and Redo

Post by ABabeNChrist »

Hi rory
That is what I was hoping for; all I needed was to get the code. HansV provided that I just haven’t tried it yet.

User avatar
rory
5StarLounger
Posts: 817
Joined: 24 Jan 2010, 15:56

Re: Code to Undo and Redo

Post by rory »

My point is that if you use the built-in controls, you don't need any code at all - they just work! :)
All you need in your CustomUI is:
<control idMso="Undo" size="large" />
<control idMso="Redo" size="large" />
Regards,
Rory

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Code to Undo and Redo

Post by ABabeNChrist »

Hi rory
Very cool I didnt know I could add controls to ribbon this way.
let me give it a try
Thank you

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Code to Undo and Redo

Post by ABabeNChrist »

Hi rory
It worked perfect, thank you
ToolBar new.JPG
You do not have the required permissions to view the files attached to this post.