remove whitespace

S

sarah

is there a way of removing all the white space from the end of a document?
from the last character onwards?
 
G

Greg Maxey

Sarah,

The following macro will eliminate trailing spaces (if any) at the end of
each paragraph and remove any empty paragraphs that creates white space
after the last character in the document:

Sub ScratchMacro()


With ActiveDocument.Range.Find
.Format = False
.Text = "^w^p"
.Replacement.Text = "^p"
.Execute Replace:=wdReplaceAll
End With
Do While ActiveDocument.Paragraphs.Last­.Range.Characters.Count = 1
ActiveDocument.Paragraphs.Last­.Range.Delete
Loop
End Sub
 
S

sarah

it's strange but im selecting text that is underlined and it is the only word
on the document and when i print it in a message box it prints as

"word
"

so i thought it meant that there were trailing lines and spaces but even
using that macro it prints the same result.

any ideas?
 
H

Helmut Weber

Hi Sarah,

there is an underlined linefeed or an underlined paragraph
mark after the word. Though Word doesn't show it on the screen!
Underline a word. Put a linefeed [shift return] in the middle
of the word. Selection the linefeed mark, which doesn't seem
to be underlined. Try:
MsgBox Selection.Font.Underline
The result is 1, underlined.

As to my macro for selecting adjacent similar formatted text,
there are most often worlds between working solutions and
perfect solutions, if there are perfect solutions at all.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 

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