Hi all,
How can I scan the word document right frm the beginning till the end.
Basically I want to remove extra (consecutive) spaces & line breaks within the word document.
Pls guide.
Printable View
Hi all,
How can I scan the word document right frm the beginning till the end.
Basically I want to remove extra (consecutive) spaces & line breaks within the word document.
Pls guide.
What do you mean "scan"? Like actually scanning a document with a scanner or search the document?
Search the document, Read the Word document character by character, so that I can remove consecutive spaces and line breaks.
Using the Content property of the document object will give you access to every character. alternativitly you can use the .Find and .Replace methods too.
The prob with the find and replace is that it has to be repeated again and again till the consecutive spaces are not eleminated...also i cant remove consecutive lines.
As far as Content property is concerend, can you give me some code snippets or links to any tutorial pages??
Thnx in advance
????
Does this help?
http://word.mvps.org/FAQs/MacrosVBA/index.htm
look under [Strings, Dates and Find and Replace]
thx...i will go thru it
koolsid...after studying the link that u provided...I do the following:
VB Code:
With WordApp .Selection.HomeKey(Word.WdUnits.wdStory) PrevChar = .Selection.Text .Selection.MoveRight(Word.WdUnits.wdCharacter, 1) Do While True If .Selection.Text = " " And .Selection.Start = 0 Then .Selection.Delete() GoTo ResumeLoop End If If PrevChar = " " And .Selection.Text = " " Then .Selection.Delete() Else PrevChar = .Selection.Text .Selection.MoveRight(Word.WdUnits.wdCharacter, 1) End If ResumeLoop: Loop
It solves my purpose...but its too slow. Is there any better method to do the same??? Basically I want to remove unwated spaces and carriage returns in the document.
For example the original text is:
| This is a text with |
| unwanted spaces and |
| line breaks |
The same as to be edited as follows:
|This is a text with unwated |
|spaces and line breaks|
I hope its clear