macro for spaces needed

B

boris

have a peculiar problem happening with a document. When
it converts to rtf (from another format, not important),
it is producing lots of extra spaces between words.
Curious if anyone can provide a simple macro text that
will search through the document for more than one space
sections and replace them with single spaces. Would help
greatly. Thanks.

Boris
 
H

Helmut Weber

Hi Boris,
like this:
Sub Makro3()
ResetSearch
With ActiveDocument.Range.Find
' .Text = " {1;}" ' German, Dutch, ;;;;; !
.Text = " {1,}" ' English ,,,,, !
.Replacement.Text = " "
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
ResetSearch
End Sub
Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
End Sub
 
K

Klaus Linke

' .Text = " {1;}" ' German, Dutch, ;;;;; !
.Text = " {1,}" ' English ,,,,, !

You can speed that up a lot if you use
' .Text = " {2;}" ' German, Dutch, ;;;;; !
.Text = " {2,}" ' English ,,,,, !

Single spaces can be left alone, and since they (probably) are very
frequent, the search will be quicker.

Regards,
Klaus
 
H

Helmut Weber

Hi Klaus,
Single spaces can be left alone, and since they (probably) are very
frequent, the search will be quicker.
got me! I'll remember that!

See you in Munich?
--
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
K

Klaus Linke

Cut down the number of possible matches, and you can speed up wildcard
replacements a lot.
Another examples of that: Restrict matches to a single paragraph by using
[!^13]@ instead of the * wildcard, if possible/sensible (and generally
avoid the * wildcard, unless you are sure it will never match a whole lot
of text).
See you in Munich?
Nov. 26? Yes... looking forward to meet you and the others!

Regards,
Klaus
 

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