Results 1 to 10 of 10
  1. #1
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Replace multiple UNDO/REDO with single (WORD 97/2000)

    I am probably asking a stupid/redundant question (since I searched for information and could not find anything).

    I have template that allows users to insert landscape pages in their normal portrait mode document. The macro that adds/inserts a landscape section has multiple VBA commands (e.g. change margins, set new style, etc) which are reflected in the UNDO/REDO lists. So the question is - is it possible to encapsulate all these VBA commands within a single UNDO/REDO command? So that everything done within the 'Insert Landscaped Section' macro is reflected in a single UNDO/REDO command.

    Thanks for your time and effort. This is a fantastic forum for people like me.

    Robie
    Thanks.
    Robie

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replace multiple UNDO/REDO with single (WORD 97/2000)

    No.

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Replace multiple UNDO/REDO with single (WORD 97/2000)

    Following text is copied from the VBA help...
    <pre>UndoClear Method

    Clears the list of actions that can be undone for the specified document.
    Corresponds to the list of items that appears when you click the arrow
    beside the Undo button on the Standard toolbar.

    Note Include this method at the end of a macro to keep Visual Basic
    actions from appearing in the Undo box
    (for example, "VBA-Selection.InsertAfter").

    Syntax
    expression.UndoClear

    expression Required. An expression that returns a Document object
    </pre>

    It doesn't do what you asked for, but may do what you need.

    StuartR

  4. #4
    Star Lounger
    Join Date
    Mar 2001
    Location
    Cheltenham, Pennsylvania, USA
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replace multiple UNDO/REDO with single (WORD 97/2000)

    I'm currently working on a job that requres frequent insertions of landscape sections, and I'm dealing with it by using AutoText. (I'm running Word 2000.) To do the same, create one mostly empty landscape section, complete with appropriate header/footer, section breaks, and even some stub contents if you like. Next, select the entire section (complete with its bordering section breaks) and copy it all to the clipboard. Now choose Insert > AutoText > AutoText and click Add. (Name the entry appropriately.) The entire landscape section will be added as an AutoText entry. Now, to insert a landscape section, you need only insert it as you would insert any other autotext item.

  5. #5
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Replace multiple UNDO/REDO with single (WORD 97/2000)

    Klaus,

    I had to read your code about 4 times before I suddenly realised how it works, I then burst out laughing <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15> very nice.

    StuartR

  6. #6
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replace multiple UNDO/REDO with single (WORD 97/2000)

    Most of it is a copy/paste job from Roemer's post.

    The empty Do ... Loop was my idea; it seemed shorter and easier than the original
    <pre>Sub EditUndo() <font color=448800>' Catches Ctrl-Z</font color=448800>
    If ActiveDocument.Undo = False Then Exit Sub
    While ActiveDocument.Bookmarks.Exists("_InMacro_")
    If ActiveDocument.Undo = False Then Exit Sub
    Wend
    End Sub</pre>

    <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22> though perhaps not quite as easy for everybody <img src=/S/question.gif border=0 alt=question width=15 height=15>

    Perhaps one could and should use a document variable instead of a bookmark, since a bookmark has a relatively good (or bad?) chance to be accidentally deleted by your macro.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

  7. #7
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replace multiple UNDO/REDO with single (WORD 97/2000)

    Hi Robie,

    I think the following solution that was developed by Roemer Lievaart is quite nifty:

    Put a bookmark into the document at the start of the macro, and remove it at the end of the macro.
    Then intercept EditUndo and EditRedo with your own macros, and make them check whether the bookmark exists.
    While the bookmark exists, these macros should continue undoing/redoing changes.

    The four macros that implement that idea are below.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

    <pre>Sub StartUndoSaver() <font color=448800>' Put "StartUndoSaver" at the beginning of your macro</font color=448800>
    On Error Resume Next
    ActiveDocument.Bookmarks.Add "_InMacro_"
    On Error GoTo 0
    End Sub</pre>

    <pre>Sub EndUndoSaver() <font color=448800>' Put "EndUndoSaver" at the end of your macro</font color=448800>
    On Error Resume Next
    ActiveDocument.Bookmarks("_InMacro_").Delete
    On Error GoTo 0
    End Sub</pre>

    <pre>Sub EditUndo() <font color=448800>' Catches Ctrl-Z</font color=448800>
    Do
    Loop While (ActiveDocument.Undo = True) _
    And ActiveDocument.Bookmarks.Exists("_InMacro_")
    End Sub</pre>

    <pre>Sub EditRedo() <font color=448800>' Catches Ctrl-Y</font color=448800>
    Do
    Loop While (ActiveDocument.Redo = True) _
    And ActiveDocument.Bookmarks.Exists("_InMacro_")
    End Sub</pre>


  8. #8
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replace multiple UNDO/REDO with single (WORD 97/2000)

    WOW! Fantastic. You guys are great.

    Klaus, Stuart, Langert and others - THANKS VERY MUCH. I don't understand the code as yet but I shall it out this week. I also like the idea of using the Autotext entry to add a landscape section. Again I shall try that out as well.

    Thanks a bunch. Few things for me to try.

    Robie
    Thanks.
    Robie

  9. #9
    Star Lounger PStepanas's Avatar
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    90
    Thanks
    4
    Thanked 2 Times in 2 Posts

    Re: Replace multiple UNDO/REDO with single (WORD 97/2000)

    Great set of macros!

    I was looking to modify them to use document variables instead of bookmarks, as Klaus suggested, but came to the conclusion that bookmarks are your best option.

    The trouble is, you need to use something who's creation/deletion will show up in the undo list. Neither document variables nor custom document properties (the other approach I tried) will do that, so the macros simply won't work.

    If only I could also override the behaviour of the Undo toolbar drop-down, but overriding command/toolbar behaviour doesn't seem to be documented at all in the usual places. I'm guessing I might need to take a look inside the CommandBars collection to find the right hook, and that's a bit too much work right now.

    Thanks for a great solution, though!

    Paulius

  10. #10
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replace multiple UNDO/REDO with single (WORD 97/2000)

    I was really impressed when I first saw Roemer Lievaart's macro solution, too.
    <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22> again re doc variables: I should have realized they wouldn't work.

    You can get the items on the Undo list:<pre> Dim myCBC As CommandBarComboBox
    Set myCBC = CommandBars.FindControl(ID:=128)
    MsgBox myCBC.ListCount, , "# of items on Undo list"
    MsgBox myCBC.List(1), , "text displayed for the most recent item"
    </pre>

    ... but I can't see how you'd be able to achieve much that way.

    I doubt you can add/remove items from the list, much less "roll" several existing items into a single item.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •