Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2005

Tip: Looking for answers? Try searching our database.

Preventing the steps to record into the undo stack

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sat - 24 May 2005 00:30 GMT
I type a simple 4-letter word in MS-Word. Then, I run a macro which
performs 1000 steps. The undo stack records the 4 characters + 1000 steps.
Is there a way in MS-Word that I can ask it to not to record only that 1000
steps into the undo stack? Any VB code is fine.

There is an article which explains as to how to clear the complete undo
stack, but that doesnt help much.
Jezebel - 24 May 2005 09:32 GMT
It's a sad failing that there are no commands for manipulating the Undo
list. All you can do is clear it completely.

>I type a simple 4-letter word in MS-Word. Then, I run a macro which
> performs 1000 steps. The undo stack records the 4 characters + 1000 steps.
[quoted text clipped - 4 lines]
> There is an article which explains as to how to clear the complete undo
> stack, but that doesnt help much.
Greg - 24 May 2005 13:00 GMT
I did find some code on Google that might work for you.

Type your four letters.  Then run the Test().  Next press CTRL+z and
the undo should only undo the macro steps.

Sub Test()
StartUndoSaver

Selection.TypeText "Hello"
Selection.TypeParagraph
Selection.Style = wdStyleHeading1
Selection.TypeText "WORLD!"
Selection.TypeParagraph

EndUndoSaver
End Sub
Sub StartUndoSaver()
   On Error Resume Next
   ActiveDocument.Bookmarks.Add "_InMacro_"
   On Error GoTo 0
End Sub
Sub EndUndoSaver()
   On Error Resume Next
   ActiveDocument.Bookmarks("_InM­acro_").Delete
   On Error GoTo 0
End Sub
Sub EditUndo() ' Catches Ctrl-Z
   If ActiveDocument.Undo = False Then Exit Sub
   While BookMarkExists("_InMacro_")
       If ActiveDocument.Undo = False Then Exit Sub
   Wend
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
Sat - 24 May 2005 16:54 GMT
Greg,

Thanks a lot.  That worked.

Sat.

> I did find some code on Google that might work for you.
>
[quoted text clipped - 39 lines]
>     On Error GoTo 0
> End Function
Sat - 24 May 2005 21:25 GMT
This method fills the undo stack and then deletes them all.  Is there a way
for the steps to not enter into the undo stack at all?

> Greg,
>
[quoted text clipped - 45 lines]
> >     On Error GoTo 0
> > End Function
Klaus Linke - 24 May 2005 22:53 GMT
Hi Sat,

You want to be able to undo them, so they have to be put on the undo stack.

Or short: No.

:-)
Klaus

> This method fills the undo stack and then deletes them all.  
> Is there a way for the steps to not enter into the undo stack at all?
[quoted text clipped - 48 lines]
>> >     On Error GoTo 0
>> > End Function
Sat - 24 May 2005 23:47 GMT
No, I dont want to undo them.  I type the 4-letter word.  After that I should
be able to say, whatever action I do after this, DO NOT enter them into the
undo stack.  Is there a way?

> Hi Sat,
>
[quoted text clipped - 57 lines]
> >> >     On Error GoTo 0
> >> > End Function
Klaus Linke - 25 May 2005 00:31 GMT
Still no :-(
For Undo to work, Word has to keep track of everything that changed, and roll the changes back one by one.

As soon as your macro makes changes (and as I understood it, it makes thousands), you're stuck.
At least the macro from Roemer Lievaart that Greg posted undoes all 1000+ changes with one Ctrl+Z.

Klaus

> No, I dont want to undo them.  I type the 4-letter word.  After that I should
> be able to say, whatever action I do after this, DO NOT enter them into the
[quoted text clipped - 61 lines]
>> >> >     On Error GoTo 0
>> >> > End Function
Alex - 30 May 2005 22:49 GMT
Unfortunately, the code below does not seem to work with the Undo/Redo drop-down buttons on the standard toolbar.
Making the various undo operations inconsistent is a big problem.

Best wishes,
Alex.

I did find some code on Google that might work for you.

Type your four letters.  Then run the Test().  Next press CTRL+z and
the undo should only undo the macro steps.

Sub Test()
StartUndoSaver

Selection.TypeText "Hello"
Selection.TypeParagraph
Selection.Style = wdStyleHeading1
Selection.TypeText "WORLD!"
Selection.TypeParagraph

EndUndoSaver
End Sub
Sub StartUndoSaver()
   On Error Resume Next
   ActiveDocument.Bookmarks.Add "_InMacro_"
   On Error GoTo 0
End Sub
Sub EndUndoSaver()
   On Error Resume Next
   ActiveDocument.Bookmarks("_InM­acro_").Delete
   On Error GoTo 0
End Sub
Sub EditUndo() ' Catches Ctrl-Z
   If ActiveDocument.Undo = False Then Exit Sub
   While BookMarkExists("_InMacro_")
       If ActiveDocument.Undo = False Then Exit Sub
   Wend
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.