PDA

View Full Version : Find text in the beginning of a paragraph and then replace the preceding CR



krishnak
10-17-2007, 05:30 PM
Hi All,

I have to format a Word doc generated from the module of a database. I have the following paragraphs in the document:

The memory for this product shall be 15 MB
Sahara Comment: 10 MB

The first paragraph specifies what the memory should be and the next paragraph specifies what the Sahara product has to offer.

I want to combine the two paragraphs to one as:

The memory for this product shall be 15 MB (10 MB)

15MB and 10 MB are separated by a tab. Such paragraphs occur frequently in a 50-page document and I want to write a macro for the same.
I have a reasonable understanding of the VBA, but I do not work with it frequently.
Finding and replacing the "Sahara Comment" is easy, but how do I go back and remove the CR as well or replace this particular CR by a Tab? And how do I put the 10 MB in parentheses?

Thanks in advance for any suggestions.

TonyJollans
10-18-2007, 02:06 AM
You should be able to do this with Find and Replace in the UI (and record code if you need it)

Find: ^13Sahara Comment: (*)^13
Replace: (\1)^p (there's a space at the beginning of that)
Check Use Wildcards (click on More... to see it if need be)

krishnak
10-18-2007, 09:03 AM
Thanks Tony for the reply.
I tried the method you suggested, but I get the message "Word has finished searching the document.The search item is not found". The text "Sahara Comment" is in italic. So in the UI, I selected Format - Font - Italic. Under the Find text box, it shows that I selected "Use Wild Cards" and "Font: Italic". I tried different combination, but the result is the same.
What exactly do you mean "(there's a space at the beginning of that)" ?
I tried a space before the Replace text.

- Krishna

TonyJollans
10-18-2007, 09:24 AM
You don't say what combinations you tried so I can't be certain, but you don't want to look for it in Italic ... the whole search string (including the preceding CR) is not in Italic so it will fail. If it fails even when you don't specify Italic, could it be that you don't have carriage returns - might they be line breaks? - if so try ^l (caret, lower case ell) instead of ^13.

The replace text is space, left parenthesis, backslash, one, right parenthesis, caret, lower case pee ... actually I just checked back and see you wanted a tab and not a space, so it should be ^t(\1)^p, that is caret, lower case tee, left parenthesis, backslash, one, right parenthesis, caret, lower case pee ... but it's all academic until the Find works!

If you keep getting stuck, can you post a sample document?

krishnak
10-18-2007, 11:40 AM
Thanks for the prompt reply.

I tried the procedure you suggested, but I am not successful. Probably I am missing something that you want me to do.
I am pasting below a small part of the doc. I did not attach a Word file because the size limit is < 20 KB which is less than the size of the blank template. Please note that "Sahara Comment" is in Italic and the rest of the text is not.
Here is the sample doc:


The purpose of this document is to define the product requirements:
Sahara Comment : SAHARA
Total internal memory:
Sahara Comment : 1.5 MB User Memory shall be available to the end user for the downloads of images.
Memory for Product Logic:
Sahara Comment : 8k
All measurments shall be made with battery included.
Length (mm)
Sahara Comment : 82mm
Width (mm)
Sahara Comment : 42mm
Thickness (mm)
Sahara Comment : 14mm
Volume (cc)
Sahara Comment : To be provided by the supplier.
Weight (g)
Sahara Comment : Target 70 grams

TonyJollans
10-18-2007, 12:42 PM
To do more I really need to see an actual document - particularly the characters that *appear as* spaces. You should be able to post a document if you zip it first.

krishnak
10-18-2007, 03:30 PM
The zip file is attached.

TonyJollans
10-18-2007, 10:58 PM
Thank you. It is, in fact, as posted here but hard to spot with the italic text.

You have a space between "Sahara Comment" and ":" - and, although not so significant, two spaces between the ":" and the following text.

You need to make the find text: ^13Sahara Comment : (*)^13 - that's caret, one, three, "Sahara Comment", space, colon, space, (perhaps another space here), left parenthesis, asterisk, right parenthesis, caret, one, three

krishnak
10-19-2007, 09:16 AM
Thank you very much, Tony, this worked like a dream. I generated the VBA code for the same and it looks pretty simple. This is really a primer for me in the use of wild cards.

- Krishna