'Group' actions in macros so they are all undone with only one 'Un

B

Bourgui

Hi all,

I have written macros that, among other things, set some bookmarks (working
in pairs) through a document that I use later with my tool.

The problem I have is that the actions of my macros are undone one by one,
So a user can launch the macro, then type some text or whatever else, then
decide to 'Undo' what they have just done. If they click one (or more) 'Undo'
too many, they can for example delete one of the bookmarks from pair.
Deleting a bookmark does not have a high-visual impact, so it usually goes
unnoticed until they call a macro which is supposed to use it and fails.

I give the example of a bookmark but it can be many other things, such as
hidden text insertion, font change...

Is there any way to group the actions of a macro (and all the functions it
may have called) so that they are all considered one action when it comes to
'Undo' and 'Redo'?

Powerpoint actually works the way I would like it to do in Word
 
J

Jay Freedman

Bourgui said:
Hi all,

I have written macros that, among other things, set some bookmarks
(working in pairs) through a document that I use later with my tool.

The problem I have is that the actions of my macros are undone one by
one, So a user can launch the macro, then type some text or whatever
else, then decide to 'Undo' what they have just done. If they click
one (or more) 'Undo' too many, they can for example delete one of the
bookmarks from pair. Deleting a bookmark does not have a high-visual
impact, so it usually goes unnoticed until they call a macro which is
supposed to use it and fails.

I give the example of a bookmark but it can be many other things,
such as hidden text insertion, font change...

Is there any way to group the actions of a macro (and all the
functions it may have called) so that they are all considered one
action when it comes to 'Undo' and 'Redo'?

Powerpoint actually works the way I would like it to do in Word

Yes, there is a way, but you have to set it up yourself. See
http://groups.google.com/group/microsoft.public.word.word97vba/msg/c5f120a7817f3dbb?hl=en

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
J

Jonathan West

Bourgui said:
Hi all,

I have written macros that, among other things, set some bookmarks
(working
in pairs) through a document that I use later with my tool.

The problem I have is that the actions of my macros are undone one by one,
So a user can launch the macro, then type some text or whatever else,
then
decide to 'Undo' what they have just done. If they click one (or more)
'Undo'
too many, they can for example delete one of the bookmarks from pair.
Deleting a bookmark does not have a high-visual impact, so it usually goes
unnoticed until they call a macro which is supposed to use it and fails.

I give the example of a bookmark but it can be many other things, such as
hidden text insertion, font change...

Is there any way to group the actions of a macro (and all the functions it
may have called) so that they are all considered one action when it comes
to
'Undo' and 'Redo'?

Powerpoint actually works the way I would like it to do in Word

You have to make a custom Undo macro, and you have to start and end each
otjher macro with some defined and detectable action, such as inserting and
removing a bookmark. if you insert a bookmark at the start of the macro and
remove it at the end, then your custom macro can undo 1 action, check
whether the bookmark is present, and repeat the process until it isn't.

If you name your custom macro EditUndo, it will be used in place of the
built-in undo command attached to the Ctrl-Z keyboard shortcut.
 
B

Bourgui

Thank you Jay and Jonathan,

I had the same idea (except with documentproperties rather than bookmarks),
but I was hoping for a more 'elegant' solution - my users could well be
working with bookmarks or document properties themselves, in fact I know some
of them are.

Would there be a way of modifying the Undo stack, without clearing it
completely like 'UndoClear' does? This way I could simply remove the X number
of actions from it when at the end of my macro. Or is it possible to set the
Undo stack to 'not capture' while my macro is running?

Thanks!
 
J

Jonathan West

Bourgui said:
Thank you Jay and Jonathan,

I had the same idea (except with documentproperties rather than
bookmarks),
but I was hoping for a more 'elegant' solution - my users could well be
working with bookmarks or document properties themselves, in fact I know
some
of them are.

Would there be a way of modifying the Undo stack, without clearing it
completely like 'UndoClear' does?

No. the stack has to contain the last action (so it can undo it) or contain
nothing. You can't selectively undo the last-item-but-37 because the 37
subsequent actions mich mean that the text that was acted on isn;t there any
more.
This way I could simply remove the X number
of actions from it when at the end of my macro. Or is it possible to set
the
Undo stack to 'not capture' while my macro is running?

No, for the same reason.
 
B

Bourgui

I see, it makes sense.

I'll see what I can come up with then using the first solution, making it
as not intrusive as possible.

Thanks to both of you!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top