Re: grouping actions for undo

From: Jay Freedman (jay.freedman_at_verizon.net)
Date: 03/12/04


Date: Fri, 12 Mar 2004 10:34:17 -0500

Hi, Roel,

Peter is correct about the best way to insert text at bookmarks. There is a
way, though, to enable a mass Undo...

A few years ago a gentleman named Roemer Lievaart posted an ingenious
method of using a bookmark to track how many Undo actions are needed
to remove the effect of a macro. See if his technique helps:

http://groups.google.com/groups?selm=387f8417.9282415%40news.xs4all.nl

-- 
Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org
Peter Hewett wrote:
> Hi Roel Vanhout
>
> You can't do it! The execution of VBA statements cannot be
> agglomerated into one atomic operation.  To accomplish what you want
> the input form normally has a Cancel button.  When the user click on
> it you unload/hide the form without updating the document.
>
> Presumably you're updating bookmarks in your document?
> InsertAfter/InsertBefore is not recommended. Use the follwoing code
> instead:
>
> Public Sub UpdateBMText(ByVal strBMName As String, _
>                         ByVal strBMValue As String)
>     Dim rngBM As Word.Range
>
>     Set rngBM = ActiveDocument.Bookmarks(strBMName).Range
>     rngBM.Text = strBMValue
>     ActiveDocument.Bookmarks.Add strBMName, rngBM
> End Sub
>
> use the code like this:
>     UpdateBMText "MyBookmarkName", "Text to go in the document"
>
> HTH + Cheers - Peter
>
>
> Roel Vanhout <roel@riks.nl>, said:
>
>> Hello all,
>>
>> This is my first attempt at writing vba things, so please excuse me
>> if I'm asking obvious things here.
>> I'm trying to do the following: when a button in the toolbar is
>> pressed, a form should show up, with some field that can be filled
>> in. When 'ok' on that form is clicked, the fields should be entered
>> into the word document with some formatting applied. I have the form
>> running and I can insert text. Because I need to do formatting I'm
>> inserting every part with Selection.InsertAfter and then I apply the
>> formatting to that part. So far so good, but I'd like to make it so
>> that when a user does this and presses 'undo' that the whole thing I
>> just inserted is removed again. Because of the multiple edit actions
>> that I do, the user has to undo every action that I did
>> programmatically, which is around 20 or so (for now). How can I
>> 'group' editing actions so that they all get undone simultaniously?
>> Thanks.
>>
>> cheers,
>>
>> roel