[VSTO] Clear undo and redo)

Source: Internet
Author: User

Recently, we developed the Open xml sdk 2.0 and VSTO on Word. When a Word file is generated, XML ing is used to bind the XML in the Content Control (ContentControl) and custom xml part (CustomXMLPart). When editing the document, VSTO is used for dynamic Word operations.

When editing a Word document, the content control (ContentControl) is dynamically added, and the xml is modified for xml ing. This will happenOne problemYes:The undo and redo operations of a Word document only affect the content control, but not the XML in the Custom xml part (CustomXMLPart )., ThinkSolutionIs to disable the Word document undo and redo operations. After google on the Internet, the undo and redo functions cannot be disabled in Word documents, and the maximum number of undo and redo stacks cannot be modified. However, the undo and redo stacks can be cleared.

 

Clear the undo stack of the current document

Sub ClearActiveDocumentUndoStack ()
ActiveDocument. UndoClear
End Sub

Clear all undo stacks that open the document

Sub ClearAllDocumentsUndoStack ()
Dim oDocUndoStack as Object
For Each oDocUndoStack In Application. Documents
ODocUndoStack. UndoClear
Next oDocUndoStack
End Sub

The Document in C # also has the corresponding UndoClear method. The undo stack is indeed cleared, and redo should be impossible, as described in the article, however, it can still be used in Word2010. I had to use a trick (trick). After UndoClear is called, just select something. Redo operations are only select operations with no adverse consequences.

Reference: WD2000: How to Clear the Undo Stack

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.