Page 1 of 1

Find/Replace multiple items

Posted: 2008-02-26 14:20:51
by mwiseman
Pretend I have no idea what I'm doing and that I know nothing about perl.

I have done "Record Marcos" in MS Word and done some editing of those macros.

If I had a series of find/replace commands, what would the structure of that be? I can figure out the regular expressions, but what would the blank object be... sort of like the shell of an html document.

My purpose is to move away from word. I get 100-200 ms word docs a month from various sources with different structures and presentational formatting. I need to get them down to lean, economical, AP style documents with limited presentational markup for import into InDesign.

I've used Word for years, but the scripting is beyond me... I'm looking for something simple and elegant. I think NWP will work, I just need the structure to get started.

Posted: 2008-02-26 14:52:08
by martin
The general structure to run multiple find & replace operations in a macro would be this:

Code: Select all

Find and Replace 'FindWhat', 'ReplaceWith', 'options'
Find and Replace 'FindWhat2', 'ReplaceWith2', 'options'
If you want to use normal Find & Replace (eg: not regular expressions / PowerFind) then the options string is simply 'a' to specify replace all, eg:

Code: Select all

Find and Replace 'Foo', 'Bar', 'a'
Find and Replace 'Red', 'Blue', 'a'
If you want to use PowerFind then you'll want to add an 'e', or a capital 'E' for PowerFind Pro, eg:

Code: Select all

Find and Replace '\$(\d+)(?!\.)', '$\1\.00', 'Ea'
Find and Replace '(?<=\s)(\d+)(?!\.)', '[\1]', 'Ea'

Posted: 2008-02-26 15:10:40
by mwiseman
So I just use simple statements according to the models you provided? No Document Declarations (as if I even know what that is) or the anything like Microsoft.Sucks.End.With?

That's almost too easy.

You're saying I could make a simple spreadsheet of the few dozen things I want to correct, write a formula to format those items into text that I save as a macro and Bob's my uncle?

Sweet.

Re: Find/Replace multiple items

Posted: 2008-09-02 08:34:46
by Matze
It was easier even: In Nisus Writer Classic you just macroized your Find/Replace String with a "macroize" button in the lower left corner of the F/R Window.
By the way: will Nisus Writer Pro have such a feature some day?

Re:

Posted: 2008-09-02 14:50:05
by martin
mwiseman wrote:So I just use simple statements according to the models you provided?
That's exactly right. There's really only one thing that I can think of that would make things more complicated for you: searching for an apostrophe or backslash. You have to "escape" the characters. So, if you wanted to replace the word "it's" you'd precede the apostrophe with a single backslash, eg:

Code: Select all

Find and Replace 'it\'s', 'it is', 'a'
Same thing for backslashes themselves, eg:

Code: Select all

Find and Replace '1\\2', 'one half', 'a'
Matze wrote:It was easier even: In Nisus Writer Classic you just macroized your Find/Replace String with a "macroize" button in the lower left corner of the F/R Window.
By the way: will Nisus Writer Pro have such a feature some day?
It should indeed- we're looking to add that feature in sometime soon.