One of my fave features in Word 2010 is the new custom undo records. It allows you to group your changes via code into blocks that can be undone in a single go – plus you can name the records.
Take the following sub:
Sub InsertSomeText()
Selection.TypeText “This is a test”
Selection.TypeParagraph
Selection.TypeText “This is some more text”
End Sub
If you ran this sub, and then went to the undo option, you’d see the 3 entries for each line of code that changed the document.
Now, here’s the same sub using a custom undo record.
Sub InsertSomeText()
Dim myUndoRecord As UndoRecord
Set myUndoRecord = Application.UndoRecord
myUndoRecord.StartCustomRecord (“My text insert to undo”)
Selection.TypeText “This is a test”
Selection.TypeParagraph
Selection.TypeText “This is some more text”
myUndoRecord.EndCustomRecord
End Sub
And after running that code, here’s what the undo options look like.
Nice!
You can also do nested undo records if you like, not that I’ve had a real need for them yet. But I may do very soon as I’m just about to do some work where I need to audit changes and have multiple levels of rolling back. Fingers crossed I’ll be able to do it all with nested undo records.
Maybe I should dig out my old Weezer CDs and listen to “Undone – The Sweater Song” when I’m working on that code! Ah, what a great song. I won’t get much coding done with Weezer belting out…