Hi there,
I have a macro that does a lot of text changes and ends with a select all - copy - select end to copy the changes to the clipboard. I then want to undo the changes, but the follwoing commands are not working in the macro. Edit:Undo or Undo or Edit:Undo Macro- but it works fine when I choose Undo from the edit menu.
Thanks
Lou
Undo a macro
- martin
- Official Nisus Person
- Posts: 5227
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: Undo a macro
Hi Lou- the "Undo" command inside a macro itself is treated differently than normal. NWP assumes you only want to undo the last step of the macro. For example, consider this macro:
The "Undo" command only undoes the "Italic" command, and thus this macro only changes whether text is bold or not.
On the other hand, once a macro has been completed, all changes it made are grouped to be a single action. That is, choosing "Undo" from the menu will undo all changes made by the macro.
Currently there's no single command that would allow you to undo all changes made by the macro from inside the macro. There's two ways you might work around this. The first is to execute the "Undo" command in your macro as many times as you need, eg:
If your macro does many things this may be error prone, but you might shorten it up like so:
That may not be terribly efficient. It might be better to work on a copy of the active document, like so:
Code: Select all
Bold
Italic
Undo
On the other hand, once a macro has been completed, all changes it made are grouped to be a single action. That is, choosing "Undo" from the menu will undo all changes made by the macro.
Currently there's no single command that would allow you to undo all changes made by the macro from inside the macro. There's two ways you might work around this. The first is to execute the "Undo" command in your macro as many times as you need, eg:
Code: Select all
Bold
Italic
Undo
Undo
Code: Select all
Bold
Italic
$undoCount = 2
While $undoCount > 0
Undo
$undoCount -= 1
End
Code: Select all
$doc = Document.active
$doc = $doc.copy
$doc.clearAndDisableUndoHistory # for efficiency, also allows closing doc at the end without any warning
# do whatever you want
$doc.close
Re: Undo a macro
That last solution creating a copy is brilliant and does exactly what I need.
Many thanks.
Lou
Many thanks.
Lou