


StrOldValue = oDoc.CustomDocumentProperties(strName).Value Name:=strName, LinkToContent:=False, Value:=Trim(strValue), _ Public Function SetCustomProp(oDoc As Document, strName As String, strValue As String) ' Purpose : Sets a custom document property Loop While (ActiveDocument.Redo = True) _ StrNewValue = ActiveDocument.Bookmarks(BM_DOC_PROP_NEW_VALUE).Range.TextĪctiveDocument.CustomDocumentProperties(strPropName).Value = strNewValue Loop While (ActiveDocument.Undo = True) _Īnd (BM_IN_MACRO) StrOldValue = ActiveDocument.Bookmarks(BM_DOC_PROP_OLD_VALUE).Range.TextĪctiveDocument.CustomDocumentProperties(strPropName).Value = strOldValue StrPropName = ActiveDocument.Bookmarks(BM_DOC_PROP_NAME).Range.Text

' Note: This macro only catches the menu command and the keyboard shortcut, Public Const BM_DOC_PROP_NEW_VALUE As String = "_DocPropNewValue_" Public Const BM_DOC_PROP_OLD_VALUE As String = "_DocPropOldValue_" Public Const BM_DOC_PROP_NAME As String = "_DocPropName_" Public Const BM_DOC_PROP_CHANGE As String = "_DocPropChange_" Public Const BM_IN_MACRO As String = "_InMacro_"
HOW TO DELETE THE ORANGE BAR IN PARETO IN EXCEL 2016 CODE
The code has been in use for quite a while With Word 2003 (it's not tested with Word 2007, so be prepared for surprise ) Option Explicit We therefore decided to replace the toolbar buttons with custom ones. Update: I forgot to clearly mention that this approach only works with the keyboard shortcuts and the menu commands, clicking the toolbar button still does a single-step undo. Document properties should not be set directly but via this macro only. However, to allow undo/redo of modifications to the document properties a special mechanism needs to be implemented using the SetCustomProp macro. This mechanism supports transactional undo/redo of all modifications done to the document content. When calling undo, we check whether the transaction mark bookmark is present and repeat the undo until the marker is gone. The start of a transaction is marked by adding a bookmark, the end is marked by removing the bookmark. You can simulate transactional behavior in Word by overwriting the Undo and Redo command routines in VBA (I don't think that overwriting built-in Word commands is possible using VSTO alone, though).
