Page 1 of 1

macro: preserve some character attributes, but add italics

Posted: 2012-11-28 06:35:40
by NisusUser
I want to change [this] to this, or [this] to this, or [this] to this, i.e. text with brackets to italicized text. However, sometimes the target text in brackets already has bold, underline or such applied. All I want is to add italics. I'm using the PowerFind Pro find and replace formula in the attached screenshot. However, if the text has other attributes applied, it removed them and adds back italics only. How can I get want I need? Do I need to do separate find/replace functions for differing text, i.e. one for text already in bold, one for text already in bold & underline, one for text that has no attributes applied yet, etc.?

Re: macro: preserve some character attributes, but add itali

Posted: 2012-11-28 07:32:21
by phspaelti
I would use a macro for this. Then rather than do Find and Replace, I would do this:

Code: Select all

Find All ...
Italic
So I'd just use the Find capability to Find things and then apply the formatting "by hand" (so to speak).
Hope this helps.

Re: macro: preserve some character attributes, but add itali

Posted: 2012-11-28 20:44:21
by NisusUser
Philip,

I guess I don't know fully the difference between Find and Replace and a macro. I was just assuming a macro was a Find and Replace expression that was saved and run as a macro. Maybe you can help me out as to what you meant.

Attached is a macro I made to do this. For some reason it doesn't work, though. I thought I followed your examples. Would you be willing to help me out?

Thanks!

Re: macro: preserve some character attributes, but add itali

Posted: 2012-11-29 05:07:28
by phspaelti
Hi I have fixed your macro.(Keeping my fingers crossed.) If you do it right then you don't need three Find/Replace statements. Your last one will suffice.
EC-brackets_to_italics_(simple).nwm
(3.09 KiB) Downloaded 851 times
What does "do it right mean"? Well the attribute sensitive find/replace pays attention to the attributes. All the attributes. So once you paste the statement into a file it takes on other attributes (paragraph style, for example), and then it stops working. The solution for such cases is to use the "Remove Attributes and Styles" command, and then add back just the attributes you want.

to be continued…

Re: macro: preserve some character attributes, but add itali

Posted: 2012-11-29 05:12:22
by phspaelti
Anyhow I hate fussing with the attributes so I suggested a second method.
EC-brackets_to_italics_(2_step).nwm
(3.14 KiB) Downloaded 899 times
As I described above, you can use Find/Replace to select things, and then apply the styles you want. As long as the Find part doesn't care about styles, this works, a bit more "reliably".

A macro can contain more than just a list of Find/Replace statements. You can add any menu commands (just type them exactly as the menu name says), and then there is a whole macro language if you want to get really elaborate.

Anyhow good luck with your macro writing. :wink:

Re: macro: preserve some character attributes, but add itali

Posted: 2012-11-29 07:04:45
by NisusUser
Thank you very much for all your help and tutoring!