Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 157053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:26:07+00:00 2026-05-11T10:26:07+00:00

I notice that Project 2007 has the functions that allow operations that can be

  • 0

I notice that Project 2007 has the functions that allow operations that can be undone to be placed in a single stack item, or ‘undo transaction’. For example:

Application.OpenUndoTransaction 'Create 6 tasks' Dim i As Integer For i = 1 To 6     ActiveProject.Tasks.Add 'UndoMe ' & i Next Application.CloseUndoTransaction  

What this means is that the user can undo all of the actions in a single undo action, rather than 6 times.

This would be great to implement in Word and/or Excel, as I’m doing some things in VSTO that make multiple changes at once, and it’ll be a bit annoying for the user if they have to click on Undo several times if they make a mistake. Although those specific functions don’t appear to exist, does anyone know if / how this can be done in some way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:26:08+00:00Added an answer on May 11, 2026 at 10:26 am

    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). The start of a transaction is marked by adding a bookmark, the end is marked by removing the bookmark.

    When calling undo, we check whether the transaction mark bookmark is present and repeat the undo until the marker is gone. Redo is working the same way. This mechanism supports transactional undo/redo of all modifications done to the document content. However, to allow undo/redo of modifications to the document properties a special mechanism needs to be implemented using the SetCustomProp macro. Document properties should not be set directly but via this macro only.

    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. We therefore decided to replace the toolbar buttons with custom ones. 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  ' string constants for Undo mechanism Public Const BM_IN_MACRO As String = '_InMacro_'  Public Const BM_DOC_PROP_CHANGE As String = '_DocPropChange_' Public Const BM_DOC_PROP_NAME As String = '_DocPropName_' Public Const BM_DOC_PROP_OLD_VALUE As String = '_DocPropOldValue_' Public Const BM_DOC_PROP_NEW_VALUE As String = '_DocPropNewValue_'  '----------------------------------------------------------------------------------- ' Procedure : EditUndo ' Purpose   : Atomic undo of macros '             Note: This macro only catches the menu command and the keyboard shortcut, '                   not the toolbar command '----------------------------------------------------------------------------------- Public Sub EditUndo() ' Catches Ctrl-Z      'On Error Resume Next     Dim bRefresh As Boolean     bRefresh = Application.ScreenUpdating     Application.ScreenUpdating = False      Do         If ActiveDocument.Bookmarks.Exists(BM_DOC_PROP_CHANGE) Then             Dim strPropName As String             Dim strOldValue As String              strPropName = ActiveDocument.Bookmarks(BM_DOC_PROP_NAME).Range.Text             strOldValue = ActiveDocument.Bookmarks(BM_DOC_PROP_OLD_VALUE).Range.Text             ActiveDocument.CustomDocumentProperties(strPropName).Value = strOldValue         End If      Loop While (ActiveDocument.Undo = True) _        And ActiveDocument.Bookmarks.Exists(BM_IN_MACRO)      Application.ScreenUpdating = bRefresh End Sub  '----------------------------------------------------------------------------------- ' Procedure : EditRedo ' Purpose   : Atomic redo of macros '             Note: This macro only catches the menu command and the keyboard shortcut, '                   not the toolbar command '----------------------------------------------------------------------------------- Public Sub EditRedo() ' Catches Ctrl-Y      Dim bRefresh As Boolean     bRefresh = Application.ScreenUpdating     Application.ScreenUpdating = False      Do         If ActiveDocument.Bookmarks.Exists(BM_DOC_PROP_CHANGE) Then             Dim strPropName As String             Dim strNewValue As String              strPropName = ActiveDocument.Bookmarks(BM_DOC_PROP_NAME).Range.Text             strNewValue = ActiveDocument.Bookmarks(BM_DOC_PROP_NEW_VALUE).Range.Text             ActiveDocument.CustomDocumentProperties(strPropName).Value = strNewValue         End If      Loop While (ActiveDocument.Redo = True) _        And ActiveDocument.Bookmarks.Exists(BM_IN_MACRO)      Application.ScreenUpdating = bRefresh  End Sub  '----------------------------------------------------------------------------------- ' Procedure : SetCustomProp ' Purpose   : Sets a custom document property '----------------------------------------------------------------------------------- Public Function SetCustomProp(oDoc As Document, strName As String, strValue As String)      Dim strOldValue As String      On Error GoTo existsAlready     strOldValue = ''     oDoc.CustomDocumentProperties.Add _         Name:=strName, LinkToContent:=False, Value:=Trim(strValue), _         Type:=msoPropertyTypeString     GoTo exitHere  existsAlready:     strOldValue = oDoc.CustomDocumentProperties(strName).Value     oDoc.CustomDocumentProperties(strName).Value = strValue  exitHere:     ' support undo / redo of changes to the document properties     'On Error Resume Next     Dim bCalledWithoutUndoSupport  As Boolean      If Not ActiveDocument.Bookmarks.Exists(BM_IN_MACRO) Then         ActiveDocument.Range.Bookmarks.Add BM_IN_MACRO, ActiveDocument.Range         bCalledWithoutUndoSupport = True     End If      Dim oRange As Range     Set oRange = ActiveDocument.Range      oRange.Collapse wdCollapseEnd     oRange.Text = ' '     oRange.Bookmarks.Add 'DocPropDummy_', oRange      oRange.Collapse wdCollapseEnd     oRange.Text = strName     oRange.Bookmarks.Add BM_DOC_PROP_NAME, oRange      oRange.Collapse wdCollapseEnd     oRange.Text = strOldValue     oRange.Bookmarks.Add BM_DOC_PROP_OLD_VALUE, oRange      oRange.Collapse wdCollapseEnd     oRange.Text = strValue     oRange.Bookmarks.Add BM_DOC_PROP_NEW_VALUE, oRange      oRange.Bookmarks.Add BM_DOC_PROP_CHANGE     ActiveDocument.Bookmarks(BM_DOC_PROP_CHANGE).Delete      Set oRange = ActiveDocument.Bookmarks(BM_DOC_PROP_NEW_VALUE).Range     ActiveDocument.Bookmarks(BM_DOC_PROP_NEW_VALUE).Delete     If Len(oRange.Text) > 0 Then oRange.Delete      Set oRange = ActiveDocument.Bookmarks(BM_DOC_PROP_OLD_VALUE).Range     ActiveDocument.Bookmarks(BM_DOC_PROP_OLD_VALUE).Delete     If Len(oRange.Text) > 0 Then oRange.Delete      Set oRange = ActiveDocument.Bookmarks(BM_DOC_PROP_NAME).Range     ActiveDocument.Bookmarks(BM_DOC_PROP_NAME).Delete     If Len(oRange.Text) > 0 Then oRange.Delete      Set oRange = ActiveDocument.Bookmarks('DocPropDummy_').Range     ActiveDocument.Bookmarks('DocPropDummy_').Delete     If Len(oRange.Text) > 0 Then oRange.Delete      If bCalledWithoutUndoSupport And ActiveDocument.Bookmarks.Exists(BM_IN_MACRO) Then         ActiveDocument.Bookmarks(BM_IN_MACRO).Delete     End If  End Function  '----------------------------------------------------------------------------------- ' Procedure : SampleUsage ' Purpose   : Demonstrates a transaction '----------------------------------------------------------------------------------- Private Sub SampleUsage()      On Error Resume Next      ' mark begin of transaction     ActiveDocument.Range.Bookmarks.Add BM_IN_MACRO      Selection.Text = 'Hello World'     ' do other stuff      ' mark end of transaction     ActiveDocument.Bookmarks(BM_IN_MACRO).Delete  End Sub 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 140k
  • Answers 140k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Place the trigger on a style for the ellipses (ellipsi?)… May 12, 2026 at 7:56 am
  • Editorial Team
    Editorial Team added an answer class Derived won't be exported by your DLL. Classes don't… May 12, 2026 at 7:56 am
  • Editorial Team
    Editorial Team added an answer I don't agree that a sequence number is always the… May 12, 2026 at 7:56 am

Related Questions

If I notice that a hash table (or any other data structure built on
In some my project I notice that during executing unit tests under VSTS2008 its
I'm running an open source project and every now and then Chinese users report
I've created a sample project to simplify my problem. I have this simple handler:

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.