Read cancellation history in VBA

I have a pretty simple VBA bit in Word 2003 that changes the font of the document to "eco-font" (long story) and brings up the Print dialog box.

When the user clicks “Cancel” or “OK”, the code performs “cancel” to return the change.

The problem is that sometimes, when I click "OK" to print the document, it is necessary to undo two actions ("change the font" and "update field"). I can not predict when this will happen.

Is there a way to read the last item in the Word undo buffer? That way, I can simply continue to undo until the font change is complete.

Edit: Final code (cut down):

ActiveDocument.Range.Bookmarks.Add ("_tempEcoUndoStart_") 
ActiveDocument.Content.Font.Name = "Nanonymus Eco Sans" 
Dialogs(wdDialogFilePrint).Show 
While ActiveDocument.Bookmarks.Exists("_tempEcoUndoStart_") 
    ActiveDocument.Undo 
Wend
+5
source share
2 answers

You can use the trick to have a "transactional" rollback in Word: at the beginning of the macro, a special bookmark is placed on the entire document. You must delete this bookmark again when you finish your macro. Now, when you call the Cancel command, repeat the cancellation until the document has a special bookmark.

The following related question has details:

Can I create a cancel transaction in Word or Excel? (ESPO)

+4
source

I have not tested, but maybe you can use UndoClear before your actions and expect to be canceled after?

ActiveDocument.UndoClear
ActiveDocument.Undo 2
0
source

All Articles