Re: Undo VBA
From: Howard Kaikow (kaikow_at_standards.com)
Date: 04/02/04
- Next message: Peter Hewett: "Re: Pagination inconsistency"
- Previous message: Howard Kaikow: "Re: Displaying a VB form in Word Document"
- In reply to: Larry: "Re: Undo VBA"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 2 Apr 2004 18:02:44 -0500
In general, it's not possible because not all Word VBA commands are
UNDOable.
There used to be a list of some of those commands in a MSFT KB article.
-- http://www.standards.com/; See Howard Kaikow's web site. "Larry" <larry328@att.net> wrote in message news:OR6hJ4NGEHA.2408@TK2MSFTNGP10.phx.gbl... > > Hi Derek, > > There is a way to do this. I don't guarantee that these are perfect > since I've messed around with them a bit. Also, I started to have a > problem whereby when I used Ctrl+Z it would occasionally undo many steps > at once. It's possible that instead of creating macros named EditUndo > and EditRedo, thus changing the built-in commands, it might be better to > give these macros different names from the built-in commands so that > they just have the specialized function of undoing/redoing macros, while > leaving the regular EditUndo/editRedo commands in their default state. > > In fact, that's what I've just done myself, and what I would recommend. > Change the macro EditUndo to UndoMacro and change the macro EditRedo to > RedoMacro, and then assign keystrokes to each one, say, Ctrl+Shift+Z to > UndoMacro and Ctrl+Shift+Y to RedoMacro. Then you're not changing the > functionality of the regular Undo/Redo commands and you won't have any > problem with them. Here goes: > > > 1. Put this at the top of your module > > Option Explicit > > 2. Then install these macros. > > ' NOTE: These macros were provided by Roemer Lievaart > ' at lievaart@dds.nl. It enables Ctrl+Z to undo an > ' entire macro in one step. It was on a web page. > > Sub StartUndoSaver() > > On Error Resume Next > > ActiveDocument.Bookmarks.Add "_InMacro_" > On Error GoTo 0 > > End Sub > > Sub EndUndoSaver() > > On Error Resume Next > ActiveDocument.Bookmarks("_InMacro_").Delete > On Error GoTo 0 > > End Sub > > Sub EditUndo() > ' Catches Ctrl-Z. Loops EditUndo until previous macro is undone. > > If ActiveDocument.Undo = False Then Exit Sub > > Do While ActiveDocument.Bookmarks.Exists("_InMacro_") > If ActiveDocument.Undo = False Then Exit Sub > Loop > > End Sub > > Sub EditRedo() > ' Catches Ctrl-Y > > If ActiveDocument.Redo = False Then Exit Sub > While BookMarkExists("_InMacro_") > If ActiveDocument.Redo = False Then Exit Sub > Wend > End Sub > > Private Function BookMarkExists(Name As String) As Boolean > On Error Resume Next > BookMarkExists = Len(ActiveDocument.Bookmarks(Name).Name) > -1 > On Error GoTo 0 > End Function > > 3. Then, in any macro that you want to be able to undo in one step, you > do this: > > Application.Run "StartUndoSaver" > > ' your code > > Application.Run "EndUndoSaver" > > > > > "Derek" <anonymous@discussions.microsoft.com> wrote in message > news:17bea01c418d1$3f957f10$a101280a@phx.gbl... > > I have several VBA routines that execute a number of > > functions. If a user decides to undo the action, they > > must undo all of the internal VBA functions. Is there a > > way to group these and include them in a single undo > > action? > > >
- Next message: Peter Hewett: "Re: Pagination inconsistency"
- Previous message: Howard Kaikow: "Re: Displaying a VB form in Word Document"
- In reply to: Larry: "Re: Undo VBA"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|