PDA

View Full Version : Keep only the first word in a line



JiJi
08-21-2008, 06:47 AM
What is the correct way to write a macro that deletes all but the first word in every line/paragraph?

I tried with a find " *^p" and replace "^p" without any success.

TonyJollans
08-21-2008, 01:30 PM
One way, with Find & Replace in the UI is:

Click on More, if need be, to see the full dialogue.
Check "Use wildcards".
In the "Find what" box, enter (<*>)*(^13)
In the "Replace with" box, enter \1\2
Hit "Replace All"

If you want VBA, just record yourself doing it.

JiJi
08-22-2008, 12:02 AM
Thank you, that got me started. I found a reference to explain the usage. Now, the first word will end before a - if there is one. Can I command characters like - or | to be included in the word?

TonyJollans
08-22-2008, 03:28 AM
You do need to specify exactly what characters are valid. Changing <*> to <[! ]@ (left angle bracket, left square bracket, exclamation mark, space, right angle bracket, at sign, space) might work - it explicitly uses a space as the trailing word delimiter.