Remove Leading Spaces

M

MG

Hi

I have a txt document that has been opened in Word that has a series of
leading spaces.
These leading spaces (always seven of them) are scattered throughout the
document.
How do I remove these quickly.
Look forward to any assistance.
 
F

fdde

why don't you just replace the seven spaces with nothing?
I just tried it and it works...
vince
 
M

MG

Hi

You are absolutely right. I tried this but used more complicated ways that
were unsuccessful. Must remember to look for the tree not the whole
forest!!!!!!

fdde said:
why don't you just replace the seven spaces with nothing?
I just tried it and it works...
vince
 
B

Birgit

Stefanie Krieger has recently posted code for search/replace in thread Soft
and Hard Return Chars and Paragraph Count. In your case this would be the
following:

With Selection.Find
.Text = " " '7 spaces
.Replacement.Text = "" 'empty string
.Forward = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With



fdde said:
why don't you just replace the seven spaces with nothing?
I just tried it and it works...
vince
 
K

Klaus Linke

A trick that might come in handy in the future:
The probably quickest way to get rid of any number of leading or trailing
whitespace is to select everything, then center, then left-align.

If you are a keyboard junkie (like me):
Ctrl+A, Ctrl+E, Ctrl+L.

Regards,
Klaus
 
J

JB

MG said:
Hi

I have a txt document that has been opened in Word that has a series of
leading spaces.
These leading spaces (always seven of them) are scattered throughout the
document.
How do I remove these quickly.
Look forward to any assistance.
If you wanted to code it for a macro button you could use something like
this. But it doesn't take into account the styles you have for these
paras...you'll have to do that part yourself (it's not that hard).

i = 0
For Each oPara In ActiveDocument.Paragraphs
ReDim Preserve Temp(i)
Temp(i) = Trim(oPara.Range.Text)
i = i + 1
Next
ActiveDocument.Range.Delete
For i = 0 To UBound(Temp())
ActiveDocument.Range.InsertAfter Temp(i)
Next


HTH

J
 
J

Jezebel

You can remove leading space from lines by searching for '^p ' and replacing
with '^p' (without the quotes). ^p is a paragraph mark. You can also use
^p^w to replace any amount of white space at the start of lines, but that
includes tab characters and you might have lines that are meant to start
with a tab.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top